Ali bin Abu Talib reported,

The Messenger of Allah ﷺ sent out a raiding party and placed a man from the Ansar in command over them, ordering them to listen to him and obey him. They angered him over something, so he said, "Gather firewood for me." They gathered it for him. Then he said, "Light a fire." They lit it. Then he said, "Did the Messenger of Allah ﷺ not command you to listen to me and obey me?"They said, "Yes, he did."He said, "Then enter it."They looked at one another and said, "We fled to the Messenger of Allah ﷺ only to escape the Fire." They remained as they were until his anger subsided and the fire went out.When they returned, they mentioned this 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 4767

Sahih

و حدثنا أبو بكر بن أبي شيبة حدثنا وكيع وأبو معاوية عن الأعمش بهذا الإسناد نحوه

مسلم 4767صحيح
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 4767
Muslim 4767