Abu Abd al-Rahman al-Sulami narrates from Sayyiduna Ali (may Allah be pleased with him) the statement of the Prophet (peace and blessings be upon him): He sent out a military detachment, appointed a commander over it and ordered the people to obey him. He lit a fire and ordered the people to jump into it. The people refused, saying that it was to escape this very fire that they did their deeds. When they returned to the Prophet (peace and blessings be upon him), he said: "Had they jumped into it, they would have kept burning in it until the Day of Resurrection. Obedience is only in what is right; there is no obedience in disobedience (to Allah)."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب قتال أهل البغي / 16609