Abdullah bin Masud reported,

The Messenger of Allah ﷺ, the truthful and trusted, told us, "The creation of each one of you is gathered in his mother's womb for forty days, then he becomes a clinging clot for the same period, then a lump of flesh for the same period. Then Allah sends the angel to him, who is commanded with four matters. He is told, 'Write down his deeds, his lifespan, his provision, and whether he will be wretched or blessed.' By the One in whose hand is my soul, 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 was written overtakes him, so he performs 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 was written overtakes him, so he performs the deeds of the people of Paradise and enters it."

Ibn Majah 76

Sahih

حدثنا علي بن محمد حدثنا وكيع ومحمد بن فضيل وأبو معاوية ح و حدثنا علي بن ميمون الرقي حدثنا أبو معاوية ومحمد بن عبيد عن الأعمش عن زيد بن وهب قال

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

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

ابن ماجه 76صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Sunnah
Chapter
Decree
Numbering
Darussalam 76
Ibn Majah 76