Abu Hurayrah (may Allah be pleased with him) reported that the Prophet (may Allah's peace and blessings be upon him) said: "Whoever obeys me has obeyed Allah, and whoever disobeys me has disobeyed Allah; and whoever obeys the leader has obeyed me, and whoever disobeys the leader has disobeyed me."
عن أبي هريرة -رضي الله عنه- مرفوعاً: «من أطاعني فقد أطاع الله، ومن عصاني فقد عصى الله، ومن يطع الأمير فقد أطاعني، ومن يعص الأمير فقد عصاني».
شرح الحديث :
The Prophet (may Allah's peace and blessings be upon him) clarified that obedience to him is obedience to Allah. The Prophet does not order his followers with anything except the legislation that Allah legislated for him and his followers. When he commands us to do something, then indeed it is from Allah's legislation. So whoever obeyed the Prophet indeed obeyed Allah, and whoever disobeys the Prophet disobyed Allah. If someone obeys the leader, then he has indeed obeyed the Prophet, and likewise, if he disobeys the leader, then he has disobeyed the Prophet; that is because the Prophet ordered obedience to the leader in many Hadīths, except if the leader's order involves disobedience (to Allah and His Messenger).