Abu Huraira reported God's Messenger as saying, “He who obeys me has obeyed God and he who disobeys me has disobeyed God; he who obeys the commander has obeyed me and he who disobeys the commander has disobeyed me. The imam is only a shield behind whom fighting is engaged in and by whom protection is sought; so if he commands piety and acts justly he will have a reward for that, but if he holds another view he will on that account be held guilty.”
(Bukhari and Muslim.)