Hakim al-Umma Mawlana Ashraf ‘Ali Thanawi (Allah have mercy on him) said,
‘There are two (major) reasons for a bad ending of life (su-e-khatimah),
First is the love of the worldly (hubb-e-dunya).
Second is to consider probable and possible things (zaniyyat) to be a definite (qatai’) article of belief.
(Explaining the second issue he added) And at the time of death the reality will be revealed. This will show that the probable and possible things he cosidered to be definite were wrong. Then the Satan will make him doubtful of his other beliefs, like tawheed and prophethood, etc. This will make him skeptical (of the basic beliefs of Islam).’
Malfozat e Hakim al-Ummat, volume 26, page 245 via Asbab su-e-khatimah aur husn-e-katimah, page 39, 40