When death befalls someone, he should know that it is an hour of serious suffering because it is a moment of severe pain, when he is leaving all objects of love, his loved ones, and to all that the horror of the throes of death and fear of where his wealth go. Then Shaytan comes and attempts to have the slave [of Allah] become discontent with his Lord, he tells him ‘Look at you! What made you die? Is it painful? You are leaving your wife, your children and you will be laid under the ground? So he might cause him to become discontent with his Lord, hating Allaah’s decree, making him say things that include any kind of objection , or he might make him unjust in his will, giving some of the inheritors preference over others, to on and so forth. In this case, we need to cure the whispers of Shaytaan and cure the self .
Abu Dawood reported from Abu al-Yusr (radiy Allaahu anhu) that the Prophet (Sallallaahu ‘alaihi wa sallam) used to say,
أعوذ بك أن يتخبطني الشيطان عند الموت
Aoodhubika an ya takhabaTani ash-Shaytaan ‘indal Mawt
“I seek refuge in You that Shaytaan flounders me at death: 
In that minute Shaytaan tells his assistants,
“If you miss him now [i.e. you do not succeed to lead him astray before he dies], you will never catch him again [i.e. you will never be able to deviate him at any other time].”
As for the cure for these trials we should first mention that whoever is mindful of Allah while in good health, Allah will protect him when he is ill, and whoever observes Allah in his thoughts, Allah will protect him when he moves his bodily parts.
“His seeking refuge in the ‘floundering of Shaytaan at death‘, that is if Shaytaan seizes him when he leaves this world, preventing him from repenting or hinders him from mending his affairs, leaving an injustice or he makes him despair from the mercy of Allaah or makes him hate death or be sorry for this life, so he becomes discontented with Allah’s decree in dissolution, going to the hereafter, so one has a bad end and he meets his Lord while he is discontented with Him.
It was narrated that the Shaytaan is never tougher on a man as in death and he tells his assistants: ‘Take this person! if you miss him today you will never catch him again.’ We seek refuge in Allah from his evil, we ask him to bless our death and to have a good end.”
 Reported by Abu Dawood 1552-1553, al-Nasa’i[8:283] through the chain of Afla’ Mawla (emancipated slave) of Abu Ayyub from Abu al-Yusr that the Prophet (Sallallaahu ‘alaihi wa sallam) used to pray, “O Allah! I seek refuge in you from dying under abolishment, not being deliberate, I seek refuge in you from drowning, from burning and from senility, I seek refuge in you that Shaytaan flounders me at death, I seek refuge in you that I die while escaping from fighting for Your sake and I seek refuge in you from dying because of a sting.”
Source: from the Book “Disciplining the Soul” by Ibn al Jawzi (rahimahullaah) , published by Dar as-Sunnah
Jinn & Devils Index Page:
Seeking Refuge in Allah from Shaitan :