The Prophet ﷺ 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 narrated it in "Itisam" (7137), and Muslim in "Imarah" (33:1835), both of them through Yunus, from Zuhri, from Abu Salama bin Abdul-Rahman, from Abu Hurairah, who mentioned it.