كتاب الإمارة
33  
The Book on Government
(53)
Chapter: The words of the prophet saws: "A Group of my Ummah will continue to Prevail on the basis of the Truth, and They will not be Harmed by those who oppose them."
(53)
باب قَوْلِهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «لاَ تَزَالُ طَائِفَةٌ مِنْ أُمَّتِي ظَاهِرِينَ عَلَى الْحَقِّ لاَ يَضُرُّهُمْ مَنْ خَالَفَهُمْ»
Sahih Muslim 1920

It has been narrated on the authority of Thauban that the Messenger of Allah (ﷺ) said:

A group of people from my Umma will always remain triumphant on the right path and continue to be triumphant (against their opponents). He who deserts them shall not be able to do them any harm. They will remain in this position until Allah's Command is executed (i.e. Qiyamah is established). In Qutaiba's version of the tradition, we do not have the words:" They will remain in this position."
حَدَّثَنَا سَعِيدُ بْنُ مَنْصُورٍ، وَأَبُو الرَّبِيعِ الْعَتَكِيُّ، وَقُتَيْبَةُ بْنُ سَعِيدٍ، قَالُوا حَدَّثَنَا حَمَّادٌ، - وَهُوَ ابْنُ زَيْدٍ - عَنْ أَيُّوبَ، عَنْ أَبِي قِلاَبَةَ، عَنْ أَبِي أَسْمَاءَ، عَنْ ثَوْبَانَ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ لاَ تَزَالُ طَائِفَةٌ مِنْ أُمَّتِي ظَاهِرِينَ عَلَى الْحَقِّ لاَ يَضُرُّهُمْ مَنْ خَذَلَهُمْ حَتَّى يَأْتِيَ أَمْرُ اللَّهِ وَهُمْ كَذَلِكَ ‏"‏ ‏.‏ وَلَيْسَ فِي حَدِيثِ قُتَيْبَةَ ‏"‏ وَهُمْ كَذَلِكَ ‏"‏ ‏.‏
Reference : Sahih Muslim 1920
In-book reference : Book 33, Hadith 245
USC-MSA web (English) reference : Book 20, Hadith 4715
  (deprecated numbering scheme)