Short answer
Yes, if the person repents before death. Allah forgives every sin, shirk included, for the one who sincerely repents and believes. What Allah does not forgive is shirk that a person dies upon without repenting; every other sin of someone who dies a believer is under His will.
Sunni creed holds that whoever dies upon shirk or kufr is not forgiven, while every lesser sin of a person who dies as a believer is under Allah's will: He may forgive it or punish it. Sincere repentance before death wipes away shirk and every other sin.
The four schools agree on this.
Explanation
The verse people worry about is this: "Indeed, Allah does not forgive association with Him, but He forgives what is less than that for whom He wills" (4:48, 4:116). The scholars agree it speaks of a person who dies upon shirk. Another verse says: "Indeed, Allah forgives all sins" (39:53), which they explain as all sins for the one who repents.
The Quran is explicit. After mentioning those who call on other gods, kill and commit zina, it says: "Except for those who repent, believe and do righteous work. For them Allah will replace their evil deeds with good" (25:70). Most of the Companions worshipped idols before Islam, and the Prophet ﷺ told 'Amr ibn al-'As that Islam wipes out what came before it. In a hadith qudsi, Allah says that if His servant came with sins nearly filling the earth, but met Him without associating anything with Him, He would meet him with as much forgiveness.
The same applies to minor shirk, such as showing off in worship, and to a Muslim who did something shirk-like out of ignorance, such as wearing an amulet believing it protects by itself. Repent, stop, say the shahada again with understanding, and move on. Do not fall into despair: despair of Allah's mercy is itself a grave sin.
Read more in does Allah forgive all sins?, tawheed, shirk and kufr, how to repent and are past sins forgiven when you convert?
The evidence
Quran, Surah An-Nisaa 4:48
إِنَّ ٱللَّهَ لَا يَغْفِرُ أَن يُشْرَكَ بِهِۦ وَيَغْفِرُ مَا دُونَ ذَٰلِكَ لِمَن يَشَآءُ ۚ وَمَن يُشْرِكْ بِٱللَّهِ فَقَدِ ٱفْتَرَىٰٓ إِثْمًا عَظِيمًا ﴿٤٨﴾
Indeed, Allah does not forgive association with Him, but He forgives what is less than that for whom He wills. And he who associates others with Allah has certainly fabricated a tremendous sin.
Shirk a person dies upon is not forgiven.
Quran, Surah Al-Furqaan 25:70
إِلَّا مَن تَابَ وَءَامَنَ وَعَمِلَ عَمَلًۭا صَٰلِحًۭا فَأُو۟لَٰٓئِكَ يُبَدِّلُ ٱللَّهُ سَيِّـَٔاتِهِمْ حَسَنَٰتٍۢ ۗ وَكَانَ ٱللَّهُ غَفُورًۭا رَّحِيمًۭا ﴿٧٠﴾
Except for those who repent, believe and do righteous work. For them Allah will replace their evil deeds with good. And ever is Allah Forgiving and Merciful.
Shows repentance removes even the gravest sins.
Quran, Surah Az-Zumar 39:53
۞ قُلْ يَٰعِبَادِىَ ٱلَّذِينَ أَسْرَفُوا۟ عَلَىٰٓ أَنفُسِهِمْ لَا تَقْنَطُوا۟ مِن رَّحْمَةِ ٱللَّهِ ۚ إِنَّ ٱللَّهَ يَغْفِرُ ٱلذُّنُوبَ جَمِيعًا ۚ إِنَّهُۥ هُوَ ٱلْغَفُورُ ٱلرَّحِيمُ ﴿٥٣﴾
Say, "O My servants who have transgressed against themselves [by sinning], do not despair of the mercy of Allah. Indeed, Allah forgives all sins. Indeed, it is He who is the Forgiving, the Merciful."
Allah forgives every sin for the one who repents.
Sahih Muslim 121
Sahih... أَنَّ الإِسْلاَمَ يَهْدِمُ مَا كَانَ قَبْلَهُ ...
"Islam wipes out what came before it."
Shows that entering Islam erases past shirk.
Jami' at-Tirmidhi 3540
Grading to be checked... لَوْ أَتَيْتَنِي بِقُرَابِ الأَرْضِ خَطَايَا ثُمَّ لَقِيتَنِي لاَ تُشْرِكُ بِي شَيْئًا ...
"If you came to Me with sins nearly filling the earth, then met Me without associating anything with Me, I would come to you with as much forgiveness."
Shows the vastness of forgiveness for one who dies free of shirk.
Where the ruling is recorded
- al-Aqida al-Tahawiyya, Section on the people of major sins. States that believers who commit major sins are under Allah's will, to forgive or punish.
- al-Aqa'id al-Nasafiyya with Sharh al-Taftazani, Section on forgiveness. States that Allah does not forgive association with Him and forgives what is below it for whom He wills.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.