كتاب الإمارة
33  
The Book on Government
(13)
Chapter: The obligation of staying with the Jama'ah (main body) of the muslims when Fitn (tribulations) appear, and in all circumstances. The prohibition of refusing to obey and on splitting away from the Jama'ah
(13)
باب الأَمْرِ بِلُزُومِ الْجَمَاعَةِ عِنْدَ ظُهُورِ الْفِتَنِ وَتَحْذِيرِ الدُّعَاةِ إِلَى الْكُفْرِ ‏‏
Sahih Muslim 1849 a

It has been narrated on the authority of Ibn 'Abbas that the messenger of Allah (ﷺ) said:

One who found in his Amir something which he disliked should hold his patience, for one who separated from the main body of the Muslims even to the extent of a handspan and then he died would die the death of one belonging to the days of Jahiliyya.
حَدَّثَنَا حَسَنُ بْنُ الرَّبِيعِ، حَدَّثَنَا حَمَّادُ بْنُ زَيْدٍ، عَنِ الْجَعْدِ أَبِي عُثْمَانَ، عَنْ أَبِي، رَجَاءٍ عَنِ ابْنِ عَبَّاسٍ، يَرْوِيهِ قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ مَنْ رَأَى مِنْ أَمِيرِهِ شَيْئًا يَكْرَهُهُ فَلْيَصْبِرْ فَإِنَّهُ مَنْ فَارَقَ الْجَمَاعَةَ شِبْرًا فَمَاتَ فَمِيتَةٌ جَاهِلِيَّةٌ ‏"‏ ‏.‏
Reference : Sahih Muslim 1849a
In-book reference : Book 33, Hadith 87
USC-MSA web (English) reference : Book 20, Hadith 4559
  (deprecated numbering scheme)