Ali bin Abu Talib reported,

The Messenger of Allah ﷺ dispatched a military expedition and placed a man from the Ansar in command over them, instructing them to listen to him and obey. They angered him over something, so he said, "Gather firewood for me." They gathered it.Then he said, "Light a fire." They lit it.Then he said, "Did the Messenger of Allah ﷺ not order you to listen to me and obey?"They replied, "Yes."He said, "Then enter it."They began looking at one another and said, "We only fled to the Messenger of Allah ﷺ from the Fire."They remained in that state until his anger subsided and the fire went out. When they returned, they mentioned the incident to the Prophet ﷺ, and he said, "Had they entered it, they would never have come out of it. Obedience is only in what is right."

Muslim 4766

Sahih

و حدثنا محمد بن عبد الله بن نمير وزهير بن حرب وأبو سعيد الأشج وتقاربوا في اللفظ قالوا حدثنا وكيع حدثنا الأعمش عن سعد بن عبيدة عن أبي عبد الرحمن

عن علي قال

بعث رسول الله ﷺ سرية واستعمل عليهم رجلا من الأنصار وأمرهم أن يسمعوا له ويطيعوا فأغضبوه في شيء فقال اجمعوا لي حطبا فجمعوا له ثم قال أوقدوا نارا فأوقدوا ثم قال ألم يأمركم رسول الله ﷺ أن تسمعوا لي وتطيعوا قالوا بلى قال فادخلوها قال فنظر بعضهم إلى بعض فقالوا إنما فررنا إلى رسول الله ﷺ من النار فكانوا كذلك وسكن غضبه وطفئت النار فلما رجعوا ذكروا ذلك للنبي ﷺ فقال لو دخلوها ما خرجوا منها إنما الطاعة في المعروف

مسلم 4766صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Leadership
Chapter
Obligation of obeying leaders in matters other than disobedience and its prohibition in disobedience
Numbering
Darussalam 4766
Muslim 4766