Imaam Ibnul Qayyim (rahimahullaah) stated:
The Shahaadah ‘None has the right to be worshiped except Allah’ (uttered) at the time of death has a great effect in wiping away evil deeds and nullifying them. That is because it is a testimony from a slave who is certain of it and has knowledge of its meaning. All his desires come to an end; his rebellious soul (becomes) mild and submissive after being in (a state of) refusal and disobedience; approving after turning away, and humbled after being held in high esteem. Its (i.e. the heart and the soul) eagerness for the worldly life and its merits departs – cut off (from everything) in the presence of its Lord, Originator and true Protector. Humble to Him, hopeful of His Pardon Forgiveness and Mercy. The Oneness of Allah frees and cuts it off from the means to Shirk and the reality of its falsity is established; so those wishes which it busied itself with cease and all its concern is (directed towards) The One it is certain to meet (i.e. Allah).
The slave entirely focuses on Allah – turning towards Allah with his heart, soul and desire; submitting to Him alone, inwardly and outwardly. His inward affair (i.e. the heart and soul) and outward affair (i.e. what he proclaims) become the same, and he sincerely says:
“None has the right to be worshiped except Allah.”
Indeed, his heart is freed from attachment to other than Allah and departs from inclining towards other than Him. All the worldly life departs from his heart and thus he is about to stand in the presence of his Lord. The intensity of his desires is extinguished and his heart is filled with the (affair) of the afterlife, so it becomes the attention of his eyes and the worldly life is (placed) behind him.
This sincere testimony becomes his last deed – purifying him of his sins and thus he is entered (into a noble position) by his Lord because he meets his Lord with a truthful and pure testimony, whose outward manifestation is in agreement with (what is hidden in the heart and soul). If he stated this (type) of testimony during the time of well-being, he would have deserted the world and its people – fleeing to Allah from the people and leaving everything else other than Him. However, he made this testimony (in the world) with a heart filled with desires, love of life and its means of subsistence…
Source: Al-Fawaa’id. Page: 91-92. Abridged and slightly paraphrased – Source