Abdul-Rahman bin Abd Rabb Kaaba reported,

I entered the masjid and found Abdullah bin Amr bin As sitting in the shade of the Kaaba with people gathered around him. I went over and sat down beside him.He said, "We were with the Messenger of Allah ﷺ on a journey. We stopped at a place, and some of us were setting up our tents, some were competing at archery, and some were tending their grazing animals, when the crier of the Messenger of Allah ﷺ called out, 'To the prayer, all together!' So we gathered before the Messenger of Allah ﷺ, and he said, 'There was never a prophet before me who was not obliged to guide his community to the best he knew for them and to warn them of the worst he knew for them. As for this community of yours, its well being has been placed in its earliest part, while its later part will be struck by affliction and by matters you will find objectionable. Trials will come, one making the next seem light by comparison. A trial will come and the believer will say, "This is the one that will destroy me," then it will pass. Another trial will come and the believer will say, "This one, this is it." So whoever wishes to be kept far from the Fire and admitted to the Garden, let death find him believing in Allah and the Last Day, and let him treat people as he would wish to be treated. And whoever pledges allegiance to a leader, giving him the clasp of his hand and the sincerity of his heart, let him obey him if he is able. If another comes contesting his authority, then strike the neck of that other one.'"I drew closer to him and said, "I adjure you by Allah, did you yourself hear this from the Messenger of Allah ﷺ?"He pointed with his hands to his ears and his heart and said, "My ears heard it and my heart retained it."I said to him, "This cousin of yours, Muawiya, orders us to consume one another's wealth unjustly and to kill one another, yet Allah says, 'You who believe, do not consume one another's wealth unjustly, but only through trade by mutual consent, and do not kill yourselves. Indeed Allah is Merciful to you' [Nisa 4:29]."He fell silent for a while, then said, "Obey him in what constitutes obedience to Allah, and disobey him in what constitutes disobedience to Allah."

Muslim 4778

Sahih

و حدثني محمد بن رافع حدثنا أبو المنذر إسمعيل بن عمر حدثنا يونس بن أبي إسحق الهمداني حدثنا عبد الله بن أبي السفر عن عامر عن عبد الرحمن بن عبد رب الكعبة الصائدي قال رأيت جماعة عند الكعبة فذكر نحو حديث الأعمش

مسلم 4778صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Leadership
Chapter
Fulfilling the pledge of allegiance to the caliphs, the first then the next
Numbering
Darussalam 4778
Muslim 4778