Mishkat al-Masabih 82
عَن عبد الله بن مَسْعُود قَالَ: حَدَّثَنَا رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ وَهُوَ الصَّادِق المصدوق: «إِن أحدكُم يجمع خلقه فِي بطن أمه أَرْبَعِينَ يَوْمًا ثمَّ يكون فِي ذَلِك علقَة مثل ذَلِك ثمَّ يكون فِي ذَلِك مُضْغَة مثل ذَلِك ثمَّ يُرْسل الْملك فينفخ فِيهِ الرّوح وَيُؤمر بِأَرْبَع كَلِمَات بكتب رزقه وأجله وَعَمله وشقي أَو سعيد فوالذي لَا إِلَه غَيره إِن أحدكُم لَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلَّا ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ فَيَدْخُلُهَا وَإِنَّ أَحَدَكُمْ لَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلَّا ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ فَيَدْخُلُهَا»
From ʿAbdullah ibn Masʿud, who said: The Messenger of Allah ﷺ, who is the truthful and the one believed, narrated to us: "The creation of each of you is gathered in his mother's womb for forty days; then he becomes in that a clinging clot for the like of that; then he becomes in that a lump of flesh for the like of that. Then the angel is sent and breathes the soul into him, and he is commanded with four words: to write his provision, his term, his deeds, and whether he is wretched or happy. By the One besides whom there is no god, one of you does the deeds of the people of Paradise until there is only a forearm's length between him and it, then the writing overtakes him and he does the deeds of the people of the Fire and enters it. And one of you does the deeds of the people of the Fire until there is only a forearm's length between him and it, then the writing overtakes him and he does the deeds of the people of Paradise and enters it."