Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said: The punishment for sin is lifted from a person by means of ten things:
1 – Repentance; this is agreed upon among the Muslims. Allaah says (interpretation of the meanings):
“Say: ‘O ‘Ibaadi (My slaves) who have transgressed against themselves (by committing evil deeds and sins)! Despair not of the Mercy of Allaah, verily, Allaah forgives all sins. Truly, He is Oft‑Forgiving, Most Merciful’”
[al-Zumar 39:53]
“Know they not that Allaah accepts repentance from His slaves and takes the Sadaqaat (alms, charity), and that Allaah Alone is the One Who forgives and accepts repentance, Most Merciful?”
[al-Tawbah 9:104]
“And He it is Who accepts repentance from His slaves, and forgives sins”
[al-Shoora 42:25]
2 – Praying for forgiveness. It was narrated in al-Saheehayn that the Prophet (peace and blessings of Allaah be upon him) said:
“If a person commits a sin, then says, ‘O Lord, I have committed a sin so forgive me,’ He says, ‘My slave knows that he has a Lord Who may forgive sins or punish for it; I have forgiven My slave…’'
(Narrated by al-Bukhaari, 6953; Muslim, 4953)
In Saheeh Muslim it is narrated that the Prophet (peace and blessings of Allaah be upon him) said: “If you did not commit sin, Allaah would do away with you and bring people who would commit sins then ask Him to forgive them, so He would forgive them.” (al-Tawbah, 4936)
3 – Doing good deeds which wipe out sins. Allaah says (interpretation of the meaning):
“And perform As‑Salaah (Iqaamat‑as‑ Salaah), at the two ends of the day and in some hours of the night [i.e. the five compulsory Salaah (prayers)]. Verily, the good deeds remove the evil deeds (i.e. small sins)”
[Hood 11:114]
And the Prophet (peace and blessings of Allaah be upon him) said: “The five daily prayers and Jumu’ah (Friday prayers) and Ramadaan take away the bad deeds between one and the next, if you avoid major sins.” (Narrated by Muslim, 344).
And he said: “Whoever fasts Ramadaan out of faith and the hope of reward, his previous sins will be forgiven.” (Narrated by al-Bukhaari, 37; Muslim, 1268).
And he said: “Whoever spends the night of Laylat al-Qadr in prayer out of faith and the hope of reward, his previous sins will be forgiven.” (Narrated by al-Bukhaari, 1768).
And he said: “Whoever performs Pilgrimage to this House, and does not behave in an obscene or immoral manner, he will go back free of sin like the day his mother gave birth to him.” (Narrated by al-Bukhaari, 1690).
And he said: “The expiation for the fitnah caused to a man by his family, wealth and children is prayer, fasting, enjoining what is good and forbidding what is evil.” (Narrated by al-Bukhaari, 494, Muslim, 5150).
And he said: “Whoever frees a believing slave, for each of (the slave’s) limbs Allaah will free one of his limbs from the Fire…” (Narrated by Muslim, 2777).
These and similar ahaadeeth are narrated in the books of Saheeh. And he said: “Charity extinguishes sin as water extinguishes fire, but hasad (malicious envy) consumes good deeds as fire consumes wood.”
4 – The du’aa’ of the believers for the believer, such as when they pray the funeral prayer for him. It was narrated from ‘Aa’ishah and Anas ibn Maalik that the Prophet (peace and blessings of Allaah be upon him) said: “There is no Muslim who dies, and a group of Muslims numbering one hundred pray for him, all of them interceding for him, but their intercession for him will be accepted.” (Narrated by Muslim, 1576).
It was narrated that Ibn ‘Abbaas said: “I heard the Messenger of Allaah (peace and blessings of Allaah be upon him) say: ‘There is no Muslim man who dies, and forty men pray the funeral prayer for him, not associating anything with Allaah, but Allaah will accept their intercession for him.’” (Narrated by Muslim, 1577). This refers to praying for him after he has died.
5 – Good deeds which can be done for the deceased, such as giving in charity (on his behalf), etc. This will benefit him, according to the clear, saheeh texts of the Sunnah and the consensus of the Imams. The same applies to freeing slaves and Hajj (on his behalf), indeed it was proven in al-Saheehayn that the Prophet (peace and blessings of Allaah be upon him) said: “Whoever dies owing any (obligatory) fasts, his heir should fast them on his behalf.” (Narrated by al-Bukhaari, 5210; Muslim, 4670).
6 – The intercession of the Prophet (peace and blessings of Allaah be upon him) and others on the Day of Resurrection for those who have committed sins. This is narrated in the mutawaatir ahaadeeth about intercession, such as the hadeeth in which he (peace and blessings of Allaah be upon him) said: “My intercession will be for those among my ummah who have committed major sins.” (Classed as saheeh by al-Albaani in Saheeh Abi Dawood, 3965). And he (peace and blessings of Allaah be upon him) said: “I was given the choice between admitting half of my ummah to Paradise and intercession, and I chose intercession.” (See Saheeh al-Jaami’, 3335).
7 – Calamities by means of which Allaah expiates sins in this world. It was narrated in al-Saheehayn that the Prophet (peace and blessings of Allaah be upon him) said: “No tiredness, exhaustion, worry, grief, distress or harm befalls a believer in this world, not even a thorn that pricks him, but Allaah expiates some of his sins thereby.” (Narrated by al-Bukhaari, 5210; Muslim, 4670).
8 – The torment, squeezing and terror that happens in the grave. These are also things by means of which sins are expiated.
9 – The horrors, distress and hardship of the Day of Resurrection.
10 – The mercy and forgiveness of Allaah, with no cause on the part of His slaves.
Source: [Majmoo’ Fataawa Ibn Taymiyah, vol. 7, p. 487-501. ]