The Messenger of Allah ﷺ said, "You should not be impressed by anyone until you see how their life ends, for a person may spend a period of his life, or a stretch of his time, doing good deeds, such that if he were to die in that state he would enter Paradise, then he changes and does evil deeds. And a servant may spend a stretch of his time doing evil deeds, such that if he were to die in that state he would enter the Fire, then he changes and does good deeds. When Allah intends good for a servant, He puts him to work before his death."They asked, "Messenger of Allah, how does He put him to work?"He replied, "He grants him success in doing a righteous deed, then takes his soul while he is in that state."
أن رسول الله ﷺ قال: لا عليكم أن لا تعجبوا بأحد حتى تنظروا بم يختم له، فإن العامل يعمل زمانا من عمره، أو برهة من دهره بعمل صالح، لو مات عليه دخل الجنة، ثم يتحول فيعمل عملا سيئا، وإن العبد ليعمل البرهة من دهر بعمل سيء، لو مات عليه دخل النار، ثم يتحول فيعمل عملا صالحا، وإذا أراد الله بعبد خيرا استعمله قبل موته قالوا: يا رسول الله، وكيف يستعمله؟ قال: يوفقه لعمل صالح، ثم يقبضه عليه.
Ahmad (12214) narrated it from Yazid bin Harun, [who said] Humayd informed us, from Anas, and he related it as mentioned.Abu Yaala (3840) and Bayhaqi in Qadar wal-Qadar (1/323) both narrated it through the route of Yazid bin Harun, with his chain of transmission, similarly. Its chain of transmission is sahih.Ibn Abu Asim also narrated it in Sunnah (393-398), and Bazzar in Kashf Astar (2157), both through routes from Humayd, with the same wording, in abridged and expanded forms.Haythami said in Majma (2117), "Ahmad, Abu Yaala, Bazzar, and Tabarani in Awsat narrated it, and its narrators are the narrators of the sahih."