وَلَيْسَتِ التَّوْبَةُ لِلَّذِينَ يَعْمَلُونَ السَّيِّئَاتِ حَتَّىٰ إِذَا حَضَرَ أَحَدَهُمُ الْمَوْتُ قَالَ إِنِّي تُبْتُ الْآنَ وَلَا الَّذِينَ يَمُوتُونَ وَهُمْ كُفَّارٌ ۚ أُولَـٰئِكَ أَعْتَدْنَا لَهُمْ عَذَابًا أَلِيمًا
But of no avail is the repentance of those who commit evil (for a lifetime) until, when one of them is visited by death, he says, “Indeed now I repent.” Nor (likewise does the repentance avail) of those who (spend their lives in unbelief and offer to repent just at the time of death, but) die as unbelievers (since such repentance is not acceptable). For such We have prepared a painful punishment. (An-Nisā’ 4:18)
The last moment of the life of a person who has not believed until that very moment—the moment when the belief of the person is no longer accepted—is called “the state of despair.” However, it is important to define the limits of this moment very well. This is the moment when it is certain both for the dying one and those around them that it is impossible for the dying one to go back to life and live long enough to believe consciously and practice it even for a very short while.
Indeed, the belief of a person is accepted provided he believes at least for a moment in full consciousness even before it is certain that the person will die. It was this moment when Prophet Muhammad, upon him be peace and blessings, offered belief to his uncle Abū Tālib. Having retained his consciousness, Abū Tālib—under the influence of the polytheist Makkans around him—responded that he was dying in the old religion of his forefathers. Another example worth mentioning is young Jewish boy who was sick. Prophet Muhammad, upon him be peace and blessings, visited the sick Jewish boy and offered him to profess “lā ilāha illa’llāh”—There is no deity but God. Then the boy looked into his father’s eyes expecting a response. The father made a gesture of acceptance. The young boy declared faith in a loud voice, repeating the words God’s Messenger said to him. Therefore, unless one does not lose one’s consciousness, the heavenly doors are open to faith.
The state of despair, that is, the moment when belief is not accepted, begins when it is certain that a sick person will die and will not have even a new conscious moment of returning to life when that person can believe. But if there is still even a little hope of return to life when one can believe consciously and practice it even by saying a good word, this may be a blessed seed to grow into a tree of blessings and rewards in the intermediate world of grave and in the Hereafter. However, if the eyes are about to close unto the world and open unto the other realm, any opportunity to believe and practice it even by saying a good word has been lost.
There are those who constantly darken their horizons with sins after they have believed. It is hoped from God’s all-encompassing mercy that they may be referents of the Divine declaration, “Say: (God gives you hope): ‘O My servants who have been wasteful (of their God-given opportunities and faculties) against (the good of) their own souls! Do not despair of God’s Mercy’” (Az-Zumar 39:53).
 Bukhārī, Mardā, 11; Abū Dāwūd, Janāiz, 2.