(Imām Bukhārī narrates): Abū al-Yamān narrated to us, he said: Shu'aib informed us, from al-Zuhrī, he said: Anas ibn Mālik al-Ansārī, may Allāh be pleased with him, informed us that:
the Messenger of Allāh ﷺ mounted a horse, so his right side was injured. Anas, may Allāh be pleased with him, narrated that one day he led us in one of the prayers while sitting, so we too prayed following him sitting. Then when he gave the salām, he said: The imām is appointed only so that he may be followed; so when he prays standing, you pray standing; and when he performs rukū', you perform rukū'; and when he raises his head from rukū', you also raise your head from rukū'; and when he performs sajdah, all of you perform sajdah; and when he says "Sami'a Allāhu liman hamidah", you say "Rabbanā wa laka al-hamd".
حَدَّثَنَا أَبُو الْيَمَانِ، قَالَ أَخْبَرَنَا شُعَيْبٌ، عَنِ الزُّهْرِيِّ، قَالَ أَخْبَرَنِي أَنَسُ بْنُ مَالِكٍ الأَنْصَارِيُّ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم رَكِبَ فَرَسًا، فَجُحِشَ شِقُّهُ الأَيْمَنُ، قَالَ أَنَسٌ ـ رضى الله عنه ـ فَصَلَّى لَنَا يَوْمَئِذٍ صَلاَةً مِنَ الصَّلَوَاتِ وَهْوَ قَاعِدٌ، فَصَلَّيْنَا وَرَاءَهُ قُعُودًا، ثُمَّ قَالَ لَمَّا سَلَّمَ " إِنَّمَا جُعِلَ الإِمَامُ لِيُؤْتَمَّ بِهِ، فَإِذَا صَلَّى قَائِمًا فَصَلُّوا قِيَامًا، وَإِذَا رَكَعَ فَارْكَعُوا، وَإِذَا رَفَعَ فَارْفَعُوا، وَإِذَا سَجَدَ فَاسْجُدُوا وَإِذَا قَالَ سَمِعَ اللَّهُ لِمَنْ حَمِدَهُ. فَقُولُوا رَبَّنَا وَلَكَ الْحَمْدُ ".
Reference: Sahih Al Bukhari 732