During the last moments of man's life, angles arrive and stand on his right side. Likewise the Satans (devils) also approach him and stand on the left side of the deathbed[1]. The job of Satans is to deceive and betray, particularly at the time of death so that, if that person has any faith, it could be destroyed. The scale of man's luck or misfortune is his last word and deed. The way in which he passes his life is the same manner and the state in which he has died, will be his state when he will be made to rise in Qiyamat. His wish at the time of his death will be what it was during his life and so he will die with the same ambitions. If in your heart there was an aspiration to see the charm of Amirul Mo-mineen (a.s.) you will be able to observe that beauty at the last moment. But if, God forbid your wish throughout your life was only the fulfilment of desire and passion then that lust of yours will become more intense at the time of death. But the one who had perfect faith is promised by God that He will protect him and Satan will not be able to gain control over him.
Allah confirms those who believe with the sure word in this world's life and in the hereafter... (14:27)
When Abu Zakaria Razi was about to die, those sitting around him asked him to recite, Laa Ilaaha Illallaah (There is no God except Allah). He replied, "I will not recite it." Then he became unconscious. When he gained sense he said, "Just now a man had come to me who said, 'If you wish to be lucky and fortunate then say: Isa is the son of God. I said, 'I will not say.' After a number of requests and denials that fellow said, 'Okay then say: There is no God but Allah.' Yet I said, 'Since you are asking me to say so I will not.' Suddenly there appeared a weapon, which killed that fellow. Now I am conscious and am reciting the Kalimah (formula of faith)." Then he recited the two formulae (Shahaadatain) and passed away from this world.
Verily, how Satan can subdue a man who had the belief that there is only one God at the time of his death? Of course the man who had been the follower of devil throughout his life will be a companion of devil on his deathbed also.
source : http://www.maaref-foundation.com