Ali bin Abu Talib reported,

The Messenger of Allah ﷺ dispatched an army and placed a man in command over them. The commander kindled a fire and ordered, "Enter it."Some people intended to enter it, while others said, "We fled from the Fire by following the Prophet, so why should we enter it?"When this was reported to the Messenger of Allah ﷺ, he said to those who had intended to enter it, "Had you entered it, you would have remained in it until the Day of Resurrection."To the others he spoke kindly and said, "There is no obedience in disobedience to Allah. Obedience is only in what is right."

Muslim 4765

Sahih

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

عن علي

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

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