Abdullah bin Masud reported,

The Messenger of Allah ﷺ, the truthful and trustworthy, told us, "Each one of you has his creation gathered in his mother's womb for forty days, then he becomes a clinging clot for a similar period, then a lump of flesh for a similar period. Then Allah sends an angel who is commanded with four matters. He is told to write down his deeds, his provision, his lifespan, and whether he will be wretched or happy. Then the soul is breathed into him.A man among you may perform the deeds of the people of Paradise until there is only an arm's length between him and Paradise, then what was written overtakes him and he performs the deeds of the people of the Fire. And another may perform the deeds of the people of the Fire until there is only an arm's length between him and the Fire, then what was written overtakes him and he performs the deeds of the people of Paradise."

Azami 8254

Sahih

عن عبد الله بن مسعود قال

حدثنا رسول الله ﷺ وهو الصادق المصدوق قال: إن أحدكم يجمع خلقه في بطن أمه أربعين يوما ثم يكون علقة مثل ذلك ثم يكون مضغة مثل ذلك ثم يبعث الله ملكا فيؤمر بأربع كلمات ويقال له اكتب عمله ورزقه وأجله وشقي أو سعيد ثم ينفخ فيه الروح، فإن الرجل منكم ليعمل حتى ما يكون بينه وبين الجنة إلا ذراع فيسبق عليه كتابه، فيعمل بعمل أهل النار، ويعمل حتى ما يكون بينه وبين النار إلا ذراع، فيسبق عليه الكتاب فيعمل بعمل أهل الجنة.

الأعظمي 8254صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Beginning of creation
Section
Creation of man
Numbering
Jami al-Kamil 8254 (2nd edition)
Azami 8254