Sahih al-Bukhari, Book 56, Hadith 168 (In-Book)

Narrated Abu Huraira: That heard Allah's Messenger saying, "We are the last but will be the foremost to enter Paradise)." The Prophet added, "He who obeys me, obeys Allah, and he who disobeys me, disobeys Allah. He who obeys the chief, obeys me, and he who disobeys the chief, disobeys me. The Imam is like a shelter for whose safety the Muslims should fight and where they should seek protection. If the Imam orders people with righteousness and rules justly, then he will be rewarded for that, and if he does the opposite, he will be responsible for that."

حَدَّثَنَا أَبُو الْيَمَانِ، أَخْبَرَنَا شُعَيْبٌ، حَدَّثَنَا أَبُو الزِّنَادِ، أَنَّ الأَعْرَجَ، حَدَّثَهُ أَنَّهُ، سَمِعَ أَبَا هُرَيْرَةَ ـ رضى الله عنه ـ أَنَّهُ سَمِعَ رَسُولَ اللَّهِ صلى الله عليه وسلم يَقُولُ ‏"‏ نَحْنُ الآخِرُونَ السَّابِقُونَ ‏"‏‏.‏ وَبِهَذَا الإِسْنَادِ ‏"‏ مَنْ أَطَاعَنِي فَقَدْ أَطَاعَ اللَّهَ، وَمَنْ عَصَانِي فَقَدْ عَصَى اللَّهَ، وَمَنْ يُطِعِ الأَمِيرَ فَقَدْ أَطَاعَنِي، وَمَنْ يَعْصِ الأَمِيرَ فَقَدْ عَصَانِي، وَإِنَّمَا الإِمَامُ جُنَّةٌ يُقَاتَلُ مِنْ وَرَائِهِ وَيُتَّقَى بِهِ، فَإِنْ أَمَرَ بِتَقْوَى اللَّهِ وَعَدَلَ، فَإِنَّ لَهُ بِذَلِكَ أَجْرًا، وَإِنْ قَالَ بِغَيْرِهِ، فَإِنَّ عَلَيْهِ مِنْهُ ‏"‏‏.‏

sunnah.com