كتاب القدر
46  
The Book of Destiny
(1)
Chapter: How The Human Being Is Created, In His Mother's Womb, And His Provision, Lifespan And Deeds Are Written Down, And His Misery and Happiness
(1)
بَاب كَيْفِيَّةِ خَلْقِ الْآدَمِيِّ فِي بَطْنِ أُمِّهِ وَكِتَابَةِ رِزْقِهِ وَأَجَلِهِ وَعَمَلِهِ وَشَقَاوَتِهِ وَسَعَادَتِهِ
Sahih Muslim 2651

Abu Huraira reported Allah's Messenger (ﷺ) as saying:

Verily, a man would perform the deeds of the people of Paradise for a long time, then his deeds would be concluded with the deeds of the people of Hell. And verily, a man would perform the deeds of the people of Hell for a long time, and then his deeds would be concluded with the deeds of the people of Paradise.
حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا عَبْدُ الْعَزِيزِ، - يَعْنِي ابْنَ مُحَمَّدٍ - عَنِ الْعَلاَءِ، عَنْ أَبِيهِ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ ‏ "‏ إِنَّ الرَّجُلَ لَيَعْمَلُ الزَّمَنَ الطَّوِيلَ بِعَمَلِ أَهْلِ الْجَنَّةِ ثُمَّ يُخْتَمُ لَهُ عَمَلُهُ بِعَمَلِ أَهْلِ النَّارِ وَإِنَّ الرَّجُلَ لَيَعْمَلُ الزَّمَنَ الطَّوِيلَ بِعَمَلِ أَهْلِ النَّارِ ثُمَّ يُخْتَمُ لَهُ عَمَلُهُ بِعَمَلِ أَهْلِ الْجَنَّةِ ‏"‏ ‏.‏
Reference : Sahih Muslim 2651
In-book reference : Book 46, Hadith 18
USC-MSA web (English) reference : Book 33, Hadith 6407
  (deprecated numbering scheme)