Narrated `Abdullah ibn Mas'ood(may Allah be pleased with him): Allah's Messengerﷺthe true and truly inspired, said, "Each one of you is constituted in the womb of the mother for forty days, and then he becomes a clot of thick blood for a similar period, and then a piece of flesh for a similar period.Then God sends an angel who is ordered to write four things. He is ordered to write down his deeds, his livelihood, the date of his death, and whether he will be blessed or wretched. Then the soul is breathed into him. One amongst you acts [like the people deserving Paradise] until between him and Paradise there remains but the distance of a cubit, when suddenly the writing of destiny overcomes him and he begins to act like the denizens of Hell and thus enters Hell, and another one acts in the way of the denizens of Hell, until there remains between him and Hell a distance of a cubit that the writing of destiny overcomes him and then he begins to act like the people of Paradise and enters Paradise.."
Allah, Exalted is He, has predestined the fate of the creation and penned it in His Preserved Tablet, so it takes place afterwards according to what He had decreed.
In this hadeeth, the Prophet ﷺ reports that the foetusgoes through four stages in the womb. The first stage, which is ovulation, takes forty days, wherein an egg and sperm travel in opposite directions to meet for implantation; hence pregnancy happens. In the second stage, it becomes a clot of thick blood clinging to the womb for a similar period. In the third stage, it develops into a piece of flesh whose size is as little as that which a human can chew in his mouth for a similar period. In the final stage, its form and shape begin after completing four months. Thereupon, Allah sends the angel that is responsible for wombs to write down all the good and evil deeds that he will do throughout his lifetime, his livelihood, the date of his death, and whether he will be blessed or wretched when he dies.Each person will die upon that which Allah has written.A person would act like the people deserving Paradise until he is so close to entering Paradise when suddenly the writing of destiny overcomes him, and he begins to act like the dwellers of Hell and thus enters Hell.And another person would act in the way of the denizens of Hell until he is so close to entering Hellfire when suddenly the writing of destiny overcomes him, and then he begins to act like the people of Paradise and enters Paradise.
This scenario is further explained in another hadeeth. It is narrated on the authority of Sahl ibn Sa’d al-Saa’idee (may Allah be pleased with him) that the Prophet ﷺ said: “that a person performs deeds like the deeds of the people of Paradise apparently before people and he would be amongst the dwellers of Hell, and a person acts apparently like the people of Hell, but (in fact) he would be among the dwellers of Paradise.” [Saheeh al-Bukhaaree and Saheeh Muslim].That means, a person who spends life in good deeds but before passing he deviates, and a person whose life is spend in bad deeds but dies upon goodness.This is because the state of such a person as it appears to people is different to that reality which Allah knows.
This hadeeth highlights the belief in fate and predestination, regarding deeds and provisions, and lifespan. It warns us from being befooled of that which is apparent to us, because deeds are judged based on how they end.
It shows that good deeds and bad deeds are just signs indicating the reality of a person and do not necessarily reflect the reality or the end of people, which Allah has predestined and decreed.