Sahih al-Bukhari 3208
Narrated `Abdullah bin Mus'ud:
Allah's Messenger (ﷺ), the true and truly inspired said, "(The matter of the Creation of) a human being is put 
together in the womb of the mother in 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 Allah sends an angel who is ordered 
to write four things. He is ordered to write down his (i.e. the new creature's) deeds, his livelihood, his 
(date of) death, and whether he will be blessed or wretched (in religion). Then the soul is breathed into 
him. So, a man amongst you may do (good deeds till there is only a cubit between him and Paradise 
and then what has been written for him decides his behavior and he starts doing (evil) deeds 
characteristic of the people of the (Hell) Fire. And similarly a man amongst you may do (evil) deeds 
till there is only a cubit between him and the (Hell) Fire, and then what has been written for him 
decides his behavior, and he starts doing deeds characteristic of the people of Paradise."
حَدَّثَنَا الْحَسَنُ بْنُ الرَّبِيعِ، حَدَّثَنَا أَبُو الأَحْوَصِ، عَنِ الأَعْمَشِ، عَنْ زَيْدِ بْنِ وَهْبٍ، قَالَ عَبْدُ اللَّهِ حَدَّثَنَا رَسُولُ اللَّهِ صلى الله عليه وسلم وَهْوَ الصَّادِقُ الْمَصْدُوقُ قَالَ ‏
"‏ إِنَّ أَحَدَكُمْ يُجْمَعُ خَلْقُهُ فِي بَطْنِ أُمِّهِ أَرْبَعِينَ يَوْمًا، ثُمَّ يَكُونُ عَلَقَةً مِثْلَ ذَلِكَ، ثُمَّ يَكُونُ مُضْغَةً مِثْلَ ذَلِكَ، ثُمَّ يَبْعَثُ اللَّهُ مَلَكًا، فَيُؤْمَرُ بِأَرْبَعِ كَلِمَاتٍ، وَيُقَالُ لَهُ اكْتُبْ عَمَلَهُ وَرِزْقَهُ وَأَجَلَهُ وَشَقِيٌّ أَوْ سَعِيدٌ‏.‏ ثُمَّ يُنْفَخُ فِيهِ الرُّوحُ، فَإِنَّ الرَّجُلَ مِنْكُمْ لَيَعْمَلُ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَ الْجَنَّةِ إِلاَّ ذِرَاعٌ، فَيَسْبِقُ عَلَيْهِ كِتَابُهُ، فَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ، وَيَعْمَلُ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَ النَّارِ إِلاَّ ذِرَاعٌ، فَيَسْبِقُ عَلَيْهِ الْكِتَابُ، فَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ ‏"‏‏.‏