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."
أن رسول الله ﷺ قال: إن الرجل ليعمل بعمل أهل الجنة، وإنه لمكتوب في الكتاب من أهل النار، فإذا كان قبل موته تحول فعمل بعمل أهل النار فمات، فدخل النار. وإن الرجل ليعمل بعمل أهل النار، وإنه لمكتوب في الكتاب من أهل الجنة، فإذا كان قبل موته تحول، فعمل بعمل أهل الجنة، فمات، فدخل الجنة.
Imam Ahmad (24762), Abu Yaala (4668), and Bayhaqi in Al-Qadar wal-Qadaa (1/322–323) all narrated it through various routes from Hammad bin Salama, from Hisham bin Urwa, from his father, from Ayesha, and he related it.Ibn Abu Asim narrated it in As-Sunnah (252), and Ibn Hibban graded it sahih (346), both of them through another route from Hisham bin Urwa, with his chain, in similar wording.Haythami mentioned it in Al-Majma (7/211–212) and said, "Ahmad and Abu Yaala narrated it through several chains, and some of these chains have narrators who are the narrators of the sahih [books]."