The Messenger of Allah, sallallahu 'alayhi wa sallam, said, "The master of invocations for forgiveness is that the servant says:
O' my 'ilah You are my Lord, there is no 'ilah but You. You created me, and I am your bondservant, and I will stick to my covenant and promise [of faith and sincere obedience] to You, as to my ability. I seek refuge in You from the evil of what I have done, I acknowledge, to You, your bounties upon me, and I acknowledge, to You, my sin. Thus forgive me, for none forgives sins except You.
Whoever says this as he enters upon evening, then, dies that night, he would enter Paradise; and if one says this as he enters upon morning, then, dies that day, he would enter Paradise." [Al-Bukhari]
The servant is always in the blessings of Allah, which necessitate thankfulness, and in sinfulness, which requires seeking forgiveness. Both of these matters are required and essential for the servant at all times, as the servant does not cease to alternate between Allah's (various) favors and blessings, and does not cease to be in need of repentance and seeking forgiveness.
This is why the Master of the Children of Adam, and the Leader of the Pious, Muhammad, sallallahu 'alayhi wa sallam, sought forgiveness in all circumstances. He said in an authentic hadith reported by Al-Bukhari:
""O people, repent to your Lord, for verily I seek forgiveness from Allah and repent to him more than seventy times in a day."
It is reported in Sahih Muslim that he said, "I seek forgiveness one hundred times in a day."
'Abdullah ibn 'Umar said, "We counted in a single sitting the Messenger of Allah, sallallahu 'alayhi wa sallam, saying one hundred times:
'My Lord, forgive me and accept my repentance, verily you are Acceptor of Repentance, Oft-Forgiving.' "
This is why seeking forgiveness was legislated at the end of actions. Allah the Exalted said:
"Those who seek forgiveness before dawn (at late night)."
Some of them said, "Give life to your nights by performing Prayer, and when the time of late night comes, concern yourself with seeking forgiveness."
It is related in the Sahih that the Prophet, sallallahu 'alayhi wa sallam, when he finished his Prayer, he would seek forgiveness three times and say:
"O' my 'ilah You are 'As-Salam (the One free from flaws), and from You comes salam (peace, or safety), blessed are Thee O' haver of glory and kindness."
Allah says:
"And seek forgiveness of Allah. Indeed, Allah is Forgiving and Merciful."
Even after the Prophet conveyed the Message, fought in the path of Allah with true jihad, and performed what Allah ordered more than anyone else, Allah commanded his Prophet (to perform istighfar), as He the Exalted said:
"When the victory of Allah has come and the conquest, and you see the people entering into the religion of Allah in multitudes, then exalt Him with praise of your Lord and ask forgiveness of Him. Indeed, He is ever Accepting of repentance."
This is why the din is established with tawhid and istighfar, as Allah the Exalted said:
"Alif Lam Ra. This is a Book whose verses are perfected an then presented in detail from One who is Wise and Acquainted. Through a messenger, saying, "Do not worship except Allah. Indeed, I am to you from Him a warner and a bringer of good tidings," and saying, "Seek forgiveness of your Lord and repent to Him, and He will let you enjoy a good provision."
And Allah says:
"So take a straight course to Him and seek His forgiveness."
And He says:
"So know (O Muhammad), that there is no deity except Allah and ask forgiveness for your sin and for the believing men and believing women."
This is why it was it came in a narration, "The Shaytan said: People are destroyed with sins, and they destroy me with 'la ilaha illallah' and seeking forgiveness." [Reported by Ibn Abi Asim and Abu Ya'la, but its chain is a fabrication]
Yunus, 'alayhis salam, said:
"There is no deity except You; exalted are You. Indeed, I have been of the wrongdoers."
The Prophet, sallallahu 'alayhi wa sallam, when he would ride his mount, he would praise Allah, then say Allahu Akbar three times, then say:
"I testify that there is no 'ilah except You, Glorified are You, I have transgressed upon myself, so forgive me."
Expiation of a gathering with which the gathering is completed is (the supplication):
"Glorified are You O' my 'ilah and I am in Your praise, I testify that there is no 'ilah except You, I ask Your forgiveness and repent unto You."
Allah knows best, and may His blessings and peace be upon the Prophet Muhammad.