Committing a sin is not something unusual; everyone makes mistakes more than once in their life. Islam, being a "Religion of Nature" (Deen-e-Fitrat), recognizes the human instinct that leads to committing mistakes and sins, though it is an extremely disliked action in Islamic teachings. Islam urges believers to avoid sins but at the same time also guides what to do when someone has done it, willingly, out of ignorance, or unintentionally. Islam guides us to immediately turn to Allah سُبْحَانَهُۥ وَتَعَالَىٰ in such a situation, seeking His mercy and forgiveness. And Allah سُبْحَانَهُۥ وَتَعَالَىٰ is always ready to forgive His servants when they turn towards Him with sincere repentance, as mentioned in the 53rd verse of Surah Az-Zumar.
Translation - Tell them, (O Prophet): “My servants who have committed excesses against themselves, do not despair of Allah's Mercy. Surely Allah forgives all sins. He is Most Forgiving, Most Merciful.
The 8th verse of Surah At-Tahreem also urges believers to turn towards Allah سُبْحَانَهُۥ وَتَعَالَىٰ and repent for sins, so He may accept your repentance.
Translation of relevant part – Believers, turn to Allah in sincere repentance; maybe your Lord will expunge your evil deeds and admit you to the Gardens beneath which rivers flow……
The concept of Allah's mercy and forgiveness for those who have committed sins and turn towards Him is further explained in Hadith 7507 of Sahih Al-Bukhari.
Translation - "If somebody commits a sin and then says, 'O my Lord! I have sinned, please forgive me!' and his Lord says, 'My slave has known that he has a Lord who forgives sins and punishes for it; I therefore have forgiven my slave (his sins).' Then he remains without committing any sin for a while and then again commits another sin and says, 'O my Lord, I have committed another sin, please forgive me,' and Allah says, 'My slave has known that he has a Lord who forgives sins and punishes for it; I therefore have forgiven my slave (his sin). Then he remains without committing any other sin for a while and then commits another sin (for the third time) and says, 'O my Lord, I have committed another sin, please forgive me,' and Allah says, 'My slave has known that he has a Lord Who forgives sins and punishes for it; I therefore have forgiven My slave (his sin); he can do whatever he likes.
Allah’s سُبْحَانَهُۥ وَتَعَالَىٰ mercy and forgiveness are unending, but the condition here is that a person admits and realizes he has committed sin, then sincerely repents and seeks His mercy. This Hadith also warns that Allah سُبْحَانَهُۥ وَتَعَالَىٰ punishes for sins if not repented.
Similarly, Hadith 2747a of Sahih Muslim narrates that Allah سُبْحَانَهُۥ وَتَعَالَىٰ is pleased when His servants repent for their sins and seek His forgiveness.
Translation - Allah is more pleased with the repentance of a servant as he turns towards Him for repentance than this: that one amongst you is upon the camel in a waterless desert, and there is upon (that camel) his provision of food and drink also and it is lost by him, and he, having lost all hope (to get that) lies down in the shadow and is disappointed about his camel and there he finds that camel standing before him. He takes hold of his nose string and then, out of boundless joy, says: 0 Lord, Thou art my servant and I am Thine Lord. He commits this mistake out of extreme delight.
So, the best way to repent and seek Allah’s سُبْحَانَهُۥ وَتَعَالَىٰ forgiveness and mercy is to make a specific Dua for forgiveness after committing a sin, with firm and sincere intention, not to repeat it in the future. The Quran and Hadith offer several Duas for repentance after committing a sin. One can recite any of these authentic Duas for forgiveness from Allah سُبْحَانَهُۥ وَتَعَالَىٰ. You can also find specific Duas after committing a sin in Islam here in the section "Hisnul Muslim”.
Praising Allah Duas
There is not any slave of Allah who commits a sin, then he perfects his ablution and stands to pray two rak'ah of prayer, then seeks Allah's forgiveness, except that Allah will forgive him.
This is the best Dua after committing a sin, as mentioned in Hadith 6306 of Sahih Al-Bukhari, and is also known as “Sayyidul Istighfar”.
This is known as the Dua of Prophet Adam عَلَيْهِ ٱلسَّلَامُ, which he recited after his expulsion from Paradise. This Dua is mentioned in the 23rd verse of Surah Al-A’raf.
Making Dua after committing a sin is a way of connecting with Allah سُبْحَانَهُۥ وَتَعَالَىٰ; therefore, it should be done with humility, sincerity, and hope in His mercy. Some of the etiquettes of reciting this Dua are as follows:
When one makes dua upon committing a sin, it is an acknowledgment that one has transgressed, and one takes responsibility for one's action. This allows people not only insight into their actions but also opens up a new door in the direction of spiritual growth. Dua is the most significant and vital means of seeking forgiveness, and when a person makes dua after committing a sin, it allows one to find a way back to their Creator. This builds a stronger connection and strengthens the faith one has in Allah.
When you realize and admit your sins, the best thing is to repent and seek Allah’s سُبْحَانَهُۥ وَتَعَالَىٰ forgiveness by reciting any of the authentic Duas, such as “Rabbana thalamna anfusana wain lam taghfir lana watarhamna lanakoonanna mina alkhasireen”
The best Dua after committing a sin, is “Allahumma anta Rabbi la ilaha illa anta, Khalaqtani wa ana `Abduka, wa ana `ala `ahdika wa wa`dika mastata`tu, A`udhu bika min Sharri ma sana`tu, abu'u Laka bini`matika `alaiya, wa abu'u laka bidhanbi faghfir lee fa innahu la yaghfiru adhdhunuba illa anta.”, which is known as “Sayyid al Istighfar” (Master of All Supplications).
Yes, you can and must make the specific Dua immediately after committing a sin and realizing you have done something sinful. But also promise not to repeat such sins in the future.
Yes, you can also make Dua in your own words after committing a sin, but only if you use respectful words, as you are talking to Allah سُبْحَانَهُۥ وَتَعَالَىٰ. That’s why it is highly recommended to recite the specific Dua for this purpose in Arabic, as mentioned in the Quran and Hadith. Thereafter, you can also say your own words in your own language, while maintaining respect and humility.
You need to repent again and keep trying to avoid repetition of sinful acts. Hadith 7507 of Sahih Al-Bukhari narrates that Allah سُبْحَانَهُۥ وَتَعَالَىٰ forgives His servants who repent sincerely, even if they commit the same sin repeatedly, after repenting. But this does not mean that you are free to repeat sinful actions; you must sincerely try to avoid sins after repentance.