Sunan Ibn Majah, Book 1, Hadith 80 (In-Book)

'Abdullah bin Mas'ud said: "The Messenger of Allah, the true and truly inspired one, told us that: 'The creation of one of you is put together in his mother's womb for forty days, then it becomes a clot for a similar length of time, then it becomes a chewed lump of flesh for a similar length of time. Then Allah sends the angel to him and commands him to write down four things. He says: "Write down his deeds, his life span, his provision, and whether he is doomed (destined for Hell) or blessed (destined for Paradise)." By the One in Whose Hand is my soul! One of you may do the deeds of the people of Paradise until there is no more than a forearm's length between him and it, then the decree overtakes him and he does the deeds of the people of Hell until there is no more than a forearm's length between him and it, then the decree overtakes him and he does the deeds of the people of Paradise until he enters therein."

حَدَّثَنَا عَلِيُّ بْنُ مُحَمَّدٍ، حَدَّثَنَا وَكِيعٌ، وَمُحَمَّدُ بْنُ فُضَيْلٍ، وَأَبُو مُعَاوِيَةَ ح وَحَدَّثَنَا عَلِيُّ بْنُ مَيْمُونٍ الرَّقِّيُّ، حَدَّثَنَا أَبُو مُعَاوِيَةَ، وَمُحَمَّدُ بْنُ عُبَيْدٍ، عَنِ الأَعْمَشِ، عَنْ زَيْدِ بْنِ وَهْبٍ، قَالَ قَالَ عَبْدُ اللَّهِ بْنُ مَسْعُودٍ حَدَّثَنَا رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ وَهُوَ الصَّادِقُ الْمَصْدُوقُ قَالَ ‏ "‏ يُجْمَعُ خَلْقُ أَحَدِكُمْ فِي بَطْنِ أُمِّهِ أَرْبَعِينَ يَوْمًا ثُمَّ يَكُونُ عَلَقَةً مِثْلَ ذَلِكَ ثُمَّ يَكُونُ مُضْغَةً مِثْلَ ذَلِكَ ثُمَّ يَبْعَثُ اللَّهُ إِلَيْهِ الْمَلَكَ فَيُؤْمَرُ بِأَرْبَعِ كَلِمَاتٍ فَيَقُولُ اكْتُبْ عَمَلَهُ وَأَجَلَهُ وَرِزْقَهُ وَشَقِيٌّ أَمْ سَعِيدٌ ‏.‏ فَوَالَّذِي نَفْسِي بِيَدِهِ إِنَّ أَحَدَكُمْ لَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلاَّ ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ فَيَدْخُلُهَا وَإِنَّ أَحَدَكُمْ لَيَعْمَلُ بِعَمَلِ أَهْلِ النَّارِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلاَّ ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ فَيَدْخُلُهَا ‏" ‏ ‏.‏

sunnah.com