The Messenger of Allah ﷺ was sitting among a group of his companions when he asked them, "Do you not know that I am the Messenger of Allah to you?"They replied, "Indeed, we bear witness that you are the Messenger of Allah."He asked, "Do you not know that whoever obeys me has obeyed Allah, and that obedience to me is part of obedience to Allah?"They replied, "Indeed, we bear witness that whoever obeys you has obeyed Allah, and that obedience to you is part of obedience to Allah."He said, "Then it is part of obedience to Allah that you obey me, and it is part of obedience to me that you obey your leaders. If they pray sitting, then pray sitting."In another wording, "your imams" appears instead of "your leaders."
أن رسول الله ﷺ كان في نفر من أصحابه، فقال: ألستم تعلمون أني رسول الله إليكم؟ قالوا: بلى نشهد أنك رسول الله قال: ألستم تعلمون أنه من أطاعني، فقد أطاع الله، ومن طاعة الله طاعتي؟ قالوا: بلى، نشهد أنه من أطاعك فقد أطاع الله، ومن طاعة الله طاعتك، قال: فإن من طاعة الله أن تطيعوني، ومن طاعتي أن تطيعوا أمرائكم، وإن صلوا قعودا فصلوا قعودا. وفي لفظ أئمتكم بدل أمرائكم.
Ahmad narrated it (5679), and Ibn Hibban graded it sahih (2109), via the route of Uqbah bin Abu Sahbaa, from Salim bin Abdullah, from Abdullah bin Umar, and he related it. Its chain of transmission is sahih, and it is cited in the Book of Prayer, in the collection of what has been reported concerning leading the prayer.