The Prophet ﷺ said, "Whoever pledges allegiance to a leader, giving him the clasp of his hand and the fruit of his heart, let him obey him to the best of his ability. If another comes to contest his authority, then strike the neck of the latter."I asked, "Did you yourself hear this from the Messenger of Allah ﷺ?"He replied, "My ears heard it and my heart retained it."I said, "This cousin of yours, Muawiya, orders us to do such and such."He answered, "Obey him in what constitutes obedience to Allah, and disobey him in what constitutes disobedience to Allah."
حدثنا مسدد حدثنا عيسى بن يونس حدثنا الأعمش عن زيد بن وهب عن عبد الرحمن بن عبد رب الكعبة
أن النبي ﷺ قال من بايع إماما فأعطاه صفقة يده وثمرة قلبه فليطعه ما استطاع فإن جاء آخر ينازعه فاضربوا رقبة الآخر قلت أنت سمعت هذا من رسول الله ﷺ قال سمعته أذناي ووعاه قلبي قلت هذا ابن عمك معاوية يأمرنا أن نفعل ونفعل قال أطعه في طاعة الله واعصه في معصية الله
Muslim narrated it in the Book of Leadership, Chapter on the Obligation of Fulfilling Allegiance to Successive Caliphs, the Earlier One Then the Next, hadith no. 1844, from the hadith of Amash, at length.