All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad is His slave and Messenger.
The repentance is accepted before the sun rises from the west and before breathing one’s last, as the Prophet said, “Allaah, the Exalted and Glorious, stretches out His Hand during the night so that the people repent for the sins that they committed during the day [from dawn till dusk], and He stretches out His Hand during the day so that the people may repent for the sins that they committed during the night [from dusk till dawn] until the sun rises from the west (before the Day of Resurrection).” [Muslim]
The Prophet also said, “Allaah accepts the repentance of a person as long as he does not breathe his last.” [Ahmad, At-Tirmithi and Ibn Maajah - Al-Albaani graded it hasan (good)]
As for the Pharaoh, uttering the words of Tawheed (pure monotheism) when he uttered them did not benefit him because he only believed when he saw the punishment and when he was dying and breathing his last, as Ibn Al-Jawzi said in his Tafseer, “Ibn Abbaas said, 'Allaah did not accept his belief when he saw the punishment.'” Ibn al-Anbaari said, “Pharaoh inclined to repentance when its door was closed as (at that time) death came to him and he saw the angels; then it was said to him {Now?}, meaning it is just now that you are repenting while you missed repentance at its due time and were among the corrupters by calling people to worship other than Allaah Almighty...”
Furthermore, Ibn Katheer said in his Tafseer:
“…The waves overtook Pharaoh and he was facing the agony of death, and while in this state (while he was dying), he said {I believe that there is no deity except that in whom the Children of Israel believe, and I am of the Muslims.}, so he believed when it was too late for him to believe, {And when they saw Our punishment, they said, "We believe in Allaah alone and disbelieve in that which we used to associate with Him." But never did their faith benefit them once they saw Our punishment. [It is] the established way of Allaah which has preceded among His servants. And the disbelievers thereupon lost [all].} [Quran 40:84-85]”
Al-Baghawi said in his Tafseer:
“But repentance is not [accepted] of those who [continue to] do evil deeds up until when death comes to one of them, and then he says, 'Indeed, I have repented now;' which is the state when his soul is being taken out of his body (breathing one’s last), as no belief will be accepted from a non-Muslim at this time, and no repentance will be accepted from a sinner at this time; Allaah says (what means): {But never did their faith benefit them once they saw Our punishment.} [Quran 40:85] It is for this reason that the faith of Pharaoh did not benefit him when drowning overtook him.”
Allaah knows best.