كتاب الإيمان
1  
The Book of Faith
(53)
Chapter: Will a person be punished for his actions during the Jahlilliyyah?
(53)
باب هَلْ يُؤَاخَذُ بِأَعْمَالِ الْجَاهِلِيَّةِ
Sahih Muslim 120 a

It is narrated on the authority of Abdullah b. Mas'ud that some people said to the Messenger of Allah (ﷺ):

Messenger of Allah, would we be held responsible for our deeds committed in the state of ignorance (before embracing Islam)? Upon his he (the Holy Prophet) remarked: He who amongst you performed good deeds in Islam, He would not be held responsible for them (misdeeds which he committed in ignorance) and he who committed evil (even after embracing Islam) would be held responsible or his misdeeds that he committed in the state of ignorance as well as in that of Islam.
حَدَّثَنَا عُثْمَانُ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا جَرِيرٌ، عَنْ مَنْصُورٍ، عَنْ أَبِي وَائِلٍ، عَنْ عَبْدِ اللَّهِ، قَالَ قَالَ أُنَاسٌ لِرَسُولِ اللَّهِ صلى الله عليه وسلم يَا رَسُولَ اللَّهِ أَنُؤَاخَذُ بِمَا عَمِلْنَا فِي الْجَاهِلِيَّةِ قَالَ ‏ "‏ أَمَّا مَنْ أَحْسَنَ مِنْكُمْ فِي الإِسْلاَمِ فَلاَ يُؤَاخَذُ بِهَا وَمَنْ أَسَاءَ أُخِذَ بِعَمَلِهِ فِي الْجَاهِلِيَّةِ وَالإِسْلاَمِ ‏"‏ ‏.‏
Reference : Sahih Muslim 120a
In-book reference : Book 1, Hadith 225
USC-MSA web (English) reference : Book 1, Hadith 217
  (deprecated numbering scheme)