Praise be to Allah.
Allah, may He be exalted, expiates sins by means of repentance, calamities, good deeds that erase sin, and other means.
Ibn al-Qayim (may Allah have mercy on him) said: The traces of sin may be erased by means of sincere repentance, heartfelt affirmation of the Oneness of Allah (Tawheed), good deeds that erase sin, calamities that expiate sin, the intercession of those who intercede among those who affirm the Oneness of Allah, and finally, if he is punished for whatever sins remain, he will be brought out of Hell by virtue of his Tawheed (affirmation of the Oneness of Allah).
End quote from Hidaayat al-Hayaari, p. 130
Good deeds that erase sin include wudoo’, the five daily prayers, and Hajj and ‘Umrah. The greatest of good deeds is Tawheed (affirmation of the Oneness of Allah), and the gravest of evil deeds is kufr (disbelief) and shirk (ascribing partners to Allah).
Saying Laa ilaaha ill-Allaah (there is no god but Allah) is the greatest of good deeds, and the most sublime of the branches of faith, as the Prophet (blessings and peace of Allah be upon him) said: “Faith has seventy-odd – or sixty-odd – branches, the best of which is saying Laa ilaaha ill-Allaah, and the least of which is removing something harmful from the road, and modesty is a branch of faith.”
Narrated by al-Bukhaari (9) and Muslim (35), from the hadeeth of Abu Hurayrah.
Muslim narrated in his Saheeh (2687) that Abu Dharr said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “Allah, may He glorified and exalted, said: Whoever does a good deed will have a ten fold reward and more, and whoever does a bad deed its recompense is one like it, or I will forgive him.”
It was narrated from Abu Sa‘eed al-Khudri (may Allah be pleased with him) that the Messenger of Allah (blessings and peace of Allah be upon him) said: “Moosa (peace be upon him) said: ‘O Lord, teach me something by which I may remember You and call upon You.’ He said: ‘Say: Laa ilaaha ill-Allaah (there is no god but Allah).’ He said: ‘O Lord, all Your slaves say that.’ He said: ‘Say: Laa ilaaha ill-Allaah.’ He said: ‘There is no god but You, my Lord, but I wanted something that is only for me.’ He said: ‘O Moosa, if the seven heavens and all their inhabitants others except Me, and the seven earths, were (placed) in one pan (of the Balance) and Laa ilaaha ill-Allah was placed in the other pan, Laa ilaaha ill-Allah would outweigh them.”
Narrated by Ibn Hibbaan (6218) and al-Haakim (1936). Al-Haakim classed it as saheeh and adh-Dhahabi agreed with him. Al-Haafiz said in al-Fath (11/208): It was narrated by an-Nasaa’i with a saheeh isnaad
This points to the virtue of these great words.
Ibn Rajab (may Allah have mercy on him) said:
If a person’s Tawheed (affirmation of the Oneness of Allah) and his sincerity towards Allah are perfect, and he fulfills all its conditions in his heart, on his lips (verbally) and in his physical actions, or in his heart and on his lips at the time of death, then forgiveness for all his previous sins becomes certain, and it will protect him from entering Hell altogether. When a person truly believes in Tawheed in his heart, and he excludes from that everything other than Allah in terms of love, veneration, glorification, awe, fear, hope and trust, in that case his sins will all be erased, even if they are like the foam of the sea, and they may be turned into good deeds. For this Tawheed is the greatest elixir; if an atom of it were to be placed on mountains of sins, it would turn them into good deeds.
End quote from Jaami‘ al-‘Uloom wa’l-Hukam, 2/417
Undoubtedly those who utter these great words will vary in status, depending on how deeply its various meanings take root in their hearts.
Ibn al-Qayyim (may Allah have mercy on him) said:
The greater a person’s Tawheed (affirmation of the Oneness of Allah), the more complete will Allah’s forgiveness of him be. Whoever meets Him not associating anything with Him at all, He will forgive him all his sins, no matter what they were, and he will not be punished for them.
We do not say that none of the people of Tawheed will enter the Fire; rather many of them will enter it because of their sins and will receive punishment commensurate with their wrongdoing, then they will be brought out of it. There is no contradiction between the two matters for the one who properly understands what we have mentioned above.
Here we will explain further the greatness of this status, because it is essential that it be understood. It should be noted that the rays of Laa ilaaha ill-Allah scatter the fog and clouds of sin in accordance with the strength or weakness of those rays. So this phrase has light, and those who believe in it vary with regard to the strength or weakness of that light, which no one knows except Allah, may He be exalted. … The greater the light of these words, the more they will dispel specious arguments and whims and desires, until the individual reaches a state where he does not encounter any specious argument, whim, desire or sin, but these rays will dispel it. This is the state of one who is actually sincere in his Tawheed and does not associate anything with Allah.
End quote from Madaarij as-Saalikeen, 1/338
The words of Allah (interpretation of the meaning), “And whosoever fears Allah and keeps his duty to Him, He will make a way for him to get out (from every difficulty). And He will provide him from (sources) he never could imagine” [at-Talaaq 65:2] offer a great promise to the pious who fear Allah.
The one who fears Allah is the one who fulfills obligatory duties and avoids things that are forbidden. That includes the one who sins, then repents and turns to Allah, and the one who goes back to sin, then repents from it again, because piety or fearing Allah, may He be exalted, means doing what is enjoined and refraining from what is forbidden. If a person repents sincerely, his bad deeds will be expiated and turned into good deeds, as Allah, may He be exalted, says (interpretation of the meaning):
“And those who invoke not any other ilaah (god) along with Allah, nor kill such person as Allah has forbidden, except for just cause, nor commit illegal sexual intercourse and whoever does this shall receive the punishment.
69. The torment will be doubled to him on the Day of Resurrection, and he will abide therein in disgrace;
70. Except those who repent and believe (in Islamic Monotheism), and do righteous deeds; for those, Allah will change their sins into good deeds, and Allah is Oft‑Forgiving, Most Merciful”
It is not stipulated that the pious one who fears Allah should be infallible and free of bad deeds, otherwise most people would be deprived of this honour and virtue. For every son of Adam sins, and the best of those who sin are those who repent. The one who sins then repents is one of the pious for whom there is the hope of the promise mentioned in the verse quoted above. The grace of Allah is vast, and what matters is that each individual should focus on striving.
And Allah knows best.