Bara bin Azib reported,

When the Messenger of Allah ﷺ arrived in Madinah, he prayed facing Bayt al-Maqdis for sixteen or seventeen months. The Messenger of Allah ﷺ wished to be directed toward the Kaabah, so Allah revealed, "We have certainly seen the turning of your face toward the heaven, so We will surely turn you to a qiblah with which you will be pleased. So turn your face toward al-Masjid al-Haram" [Baqarah 2:144]. He was then turned toward the Kaabah, which he loved.A man prayed the afternoon prayer with him, then passed by some people from the Ansar who were in the bowing position during the afternoon prayer, facing Bayt al-Maqdis. He told them that he bore witness that he had prayed with the Messenger of Allah ﷺ and that he had been directed toward the Kaabah. So they turned while still bowing.

Tirmidhi 2962

Sahih

حدثنا هناد حدثنا وكيع عن إسرائيل عن أبي إسحق

عن البراء بن عازب قال

لما قدم رسول الله ﷺ المدينة صلى نحو بيت المقدس ستة أو سبعة عشر شهرا وكان رسول الله ﷺ يحب أن يوجه إلى الكعبة فأنزل الله {قد نرى تقلب وجهك في السماء فلنولينك قبلة ترضاها فول وجهك شطر المسجد الحرام} فوجه نحو الكعبة وكان يحب ذلك فصلى رجل معه العصر قال ثم مر على قوم من الأنصار وهم ركوع في صلاة العصر نحو بيت المقدس فقال هو يشهد أنه صلى مع رسول الله ﷺ وأنه قد وجه إلى الكعبة قال فانحرفوا وهم ركوع

الترمذي 2962صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Tafsir of the Quran
Chapter
From Surah Baqarah
Numbering
Darussalam 2962
Tirmidhi 2962