Sahih Muslim Book 20, Hadith Number 4519.

Chapter : Obedience to the ruler is forbidden in matters sinful, but is otherwise obligatory.

It has been narrated on the authority of Abu Huraira that the Messenger of Allah (may peace be upon him) said: Whoso obeys me obeys God; and whose disobeys me disobeys God. Whoso obeys my commander obeys me, and whoso disobeys my commander disobeys me.