Ayesha reported,

The Messenger of Allah ﷺ said, "A man may perform the deeds of the people of Paradise, while in truth he is recorded in the Book among the people of the Fire. Then, just before his death, he changes course and performs the deeds of the people of the Fire, and so he dies and enters the Fire. And a man may perform the deeds of the people of the Fire, while in truth he is recorded in the Book among the people of Paradise. Then, just before his death, he changes course and performs the deeds of the people of Paradise, and so he dies and enters Paradise."

Azami 1046

Sahih

عن عائشة

أن رسول الله ﷺ قال: إن الرجل ليعمل بعمل أهل الجنة، وإنه لمكتوب في الكتاب من أهل النار، فإذا كان قبل موته تحول فعمل بعمل أهل النار فمات، فدخل النار. وإن الرجل ليعمل بعمل أهل النار، وإنه لمكتوب في الكتاب من أهل الجنة، فإذا كان قبل موته تحول، فعمل بعمل أهل الجنة، فمات، فدخل الجنة.

الأعظمي 1046صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Faith
Chapter
Belief in the divine decree and predestination
Section
Actions are judged by their endings
Numbering
Jami al-Kamil 1046 (2nd edition)
Azami 1046