Tafsir Ibn Kathir -> Surah Al-Baqarah -> Adhering to Tawhid until Death

Allah said,

﴿يَـبَنِىَّ إِنَّ اللَّهَ اصْطَفَى لَكُمُ الدِّينَ فَلاَ تَمُوتُنَّ إَلاَّ وَأَنتُم مُّسْلِمُونَ﴾

((Saying), "O my sons! Allah has chosen for you the (true) religion, then die not except as Muslims.'') meaning, perform righteous deeds during your lifetime and remain on this path, so that Allah will endow you with the favor of dying upon it. Usually, one dies upon the path that he lived on and is resurrected according to what he died on. Allah, the Most Generous, helps those who seek to do good deeds to remain on the righteous path.

This by no means contradicts the authentic Hadith that says,

«إِنَّ الرَّجُلَ لَيَعْمَلُ بِعَمَلِ أَهْلِ الْجَنَّةِ حَتّـى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلَّا بَاعٌ أَوْ ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعمَلُ بِعَمَلِ أَهْلِ النَّار فَيَدْخُلُهَا. وَإِنَّ الرَّجُلَ لَيَعْمَلُ بعَمَلِ أَهلِ النَّارِ حَتَّى مَا يَكُونُ بَيْنَهُ وَبَيْنَهَا إِلَّا بَاعٌ أَو ذِرَاعٌ فَيَسْبِقُ عَلَيْهِ الْكِتَابُ فَيَعْمَلُ بعَمَلِ أَهْلِ الْجَنَّةِ فَيَدْخُلُهَا»

(Man might perform the works of the people of Paradise until only a span of outstretched arms or a cubit separates him from it, then the Book (destiny) takes precedence, and he performs the works of the people of the Fire and thus enters it. Also, man might perform the works of the people of the Fire until only a span of outstretched arms or a cubit separates him from the Fire, but the Book takes precedence and he performs the works of the people of Paradise and thus enters it.) Allah said, (92:5-10),

﴿فَأَمَّا مَنْ أَعْطَى وَاتَّقَى - وَصَدَّقَ بِالْحُسْنَى - فَسَنُيَسِّرُهُ لِلْيُسْرَى - وَأَمَّا مَن بَخِلَ وَاسْتَغْنَى - وَكَذَّبَ بِالْحُسْنَى - فَسَنُيَسِّرُهُ لِلْعُسْرَى ﴾

(As for him who gives (in charity) and keeps his duty to Allah and fears Him. And believes in Al-Husna. We will make smooth for him the path of ease (goodness). But he who is a greedy miser and thinks himself self-sufficient. And belies Al-Husna (none has the right to be worshipped except Allah). We will make smooth for him the path for evil),

﴿أَمْ كُنتُمْ شُهَدَآءَ إِذْ حَضَرَ يَعْقُوبَ الْمَوْتُ إِذْ قَالَ لِبَنِيهِ مَا تَعْبُدُونَ مِن بَعْدِى قَالُواْ نَعْبُدُ إِلَـهَكَ وَإِلَـهَ آبَآئِكَ إِبْرَهِيمَ وَإِسْمَـعِيلَ وَإِسْحَـقَ إِلَـهًا وَاحِدًا وَنَحْنُ لَهُ مُسْلِمُونَ - تِلْكَ أُمَّةٌ قَدْ خَلَتْ لَهَا مَا كَسَبَتْ وَلَكُم مَّا كَسَبْتُم وَلاَ تُسْـَلُونَ عَمَّا كَانُوا يَعْمَلُونَ ﴾

n(133. Or were you witnesses when death approached Ya`qub (Jacob) When he said unto his sons, "What will you worship after me'' They said, "We shall worship your AIlah (God ـ Allah) the Ilah of your fathers, Ibrahim (Abraham), Isma`il (Ishmael), Ishaq (Isaac), One Ilah, and to Him we submit (in Islam)).'' (134. That was a nation who has passed away. They shall receive the reward of what they earned and you of what you earn. And you will not be asked of what they used to do.)