Allah The Almighty exhorts the believers to seek forgiveness and race each other on the road leading to repentance and rewards, so that one does not despair and give up on the Mercy of Allah The Almighty. He Says (what means): {And march forth in the way (which leads to) forgiveness from your Lord, and for Paradise as wide as the heavens and the earth, prepared for the pious.} [Quran 3:133]
The following are some means leading to forgiveness of sins and gaining the closeness and Mercy of Allah The Almighty based on evidence from the Quran and Ahaadeeth (Prophetic narrations).
Accepting Islam
Allah The Almighty Says (what means): {Say to those who have disbelieved, if they cease (from disbelief), their past will be forgiven. But if they return (thereto), then the examples of those (punished) before them have already preceded (as a warning).} [Quran 8:38]
‘Amr ibn Al-‘Aas narrated that the Prophet said: “Did you not know that one's [acceptance of] Islam obliterates whatever he did before it?” [Muslim]
Migration
This means to relocate from the land of disbelief to the land of Islam. Allah The Almighty Says (what means): {Then, verily! Your Lord -- for those who emigrated after they had been put to trials and thereafter strove hard and fought (for the Cause of Allah) and were patient, verily, your Lord afterward is, Oft-Forgiving, Most Merciful.} [Quran 16:110]
'Amr ibn Al-‘Aas narrated that the Prophet said: “Migration expiates whatever was before it.” [Muslim]
An accepted Hajj
'Amr ibn Al-‘Aas narrated that the Prophet said: “An accepted Hajj removes whatever was before it [of sins].” [Muslim]
Abu Hurayrah narrated that the Prophet said: “He who performs Hajj and does not involve (himself) in sexual relations or a sin (during the Hajj), will return from Hajj in a state just like the one his mother gave birth to him in (i.e., free from sins).” [Al-Bukhari]
Supplication upon hearing the Athaan (call to prayer)
Sa’d ibn Abi Waqqaas narrated that the Prophet said: “He who says upon hearing the person calling the Athaan, ‘I also bear witness that none has the right to be worshipped except Allah alone without a partner, and that Muhammad is His slave and messenger. I accept Allah as a Lord, Muhammad as a messenger, and Islam as a religion’ -- all his previous sins will be forgiven.” [Muslim]
Coinciding with the angels when saying 'Aameen'
Abu Hurayrah narrated that the Prophet said: “When the Imam says 'Aameen', say 'Aameen', because he who coincides with the angels when saying Aameen will have all his previous sins forgiven.” [Al-Bukhari and Muslim]
Coinciding with the angels when saying ‘Our lord for you is all the praise’
The Prophet said: “When the Imam says, ‘Allah hears he who praises Him’, say, ‘Our Lord for You is all the praise’, because he who coincides with the angels when saying so will have all his previous sins forgiven.” [Al-Bukhari and Muslim]
Praying two Rak’ah (units) of prayer attentively
The Prophet said: “He who properly performs ablution, then prays any two Rak’ah (of Salah) without being heedless, will get all his previous sins forgiven.” [Ahmad]
Gathering in circles of Thikr (mentioning Allah The Almighty)
Sahl ibn Hanthalah narrated that the Prophet said: “It never happens that a group of people gather to mention Allah, but they will be told upon leaving the circle (after finishing): 'Your sins have been forgiven.'” [Ahmad]
Being afflicted by sickness
The Mother of the Believers, ‘Aa’ishah narrated that the Prophet said: “Whenever a believer becomes sick, he will be purified from his sins, just as fire purifies steel.” [Al-Bukhari]