The Messenger of Allah ﷺ said, "Whoever obeys me has obeyed Allah, and whoever disobeys me has disobeyed Allah. Whoever obeys my appointed leader has obeyed me, and whoever disobeys my appointed leader has disobeyed me."
أن رسول الله ﷺ قال: من أطاعني فقد أطاع الله، ومن عصاني فقد عصى الله، ومن أطاع أميري فقد أطاعني، ومن عصى أميري فقد عصاني.
Bukhari reported it in the Book of Rulings (7137), and Muslim reported it in the Book of Leadership (33:1835), both through the route of Abdullah bin Wahb, who said, Yunus told me, from Ibn Shihab, who said, Abu Salama bin Abdul-Rahman narrated to us, from Abu Hurairah, and he mentioned it.As for His saying, "But if you turn away, then upon him is only what he is charged with, and upon you is what you are charged with" [Nur 24:54], this means that upon the Messenger is what he was tasked with, namely conveying the call and delivering the message, and upon you is what you were tasked with, namely responding, accepting, and obeying Allah and the Messenger ﷺ.This is likewise the relationship between the shepherd and the flock, each one carries out what he has been tasked with, as has come in the hadith.