Abdullah bin Masud reported,

The Messenger of Allah ﷺ, who is the truthful and the trusted, narrated to 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 he becomes a lump of flesh for a similar period. Then Allah sends to him the angel, who breathes the soul into him and is commanded with four matters, to record his sustenance, his lifespan, his deeds, and whether he will be wretched or blessed.By the One besides whom there is no god, one of you may perform the deeds of the people of Paradise until there is only an arm's length between him and it, then what has been written overtakes him, so he ends with the deeds of the people of the Fire and enters it. And one of you may perform the deeds of the people of the Fire until there is only an arm's length between him and it, then what has been written overtakes him, so he ends with the deeds of the people of Paradise and enters it."

Tirmidhi 2137

Sahih

حدثنا هناد حدثنا أبو معاوية عن الأعمش عن زيد بن وهب

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

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

الترمذي 2137صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Decree
Chapter
Deeds being judged by their endings
Numbering
Darussalam 2137
Tirmidhi 2137