Bara bin Azib reported,

When the Messenger of Allah ﷺ arrived in Medina, he prayed facing Bayt al-Maqdis for sixteen or seventeen months, though the Messenger of Allah ﷺ longed to face the Kaabah. So Allah Most High revealed, "Indeed, We see 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 the Sacred Mosque" [Baqarah 2:144]. He then turned toward the Kaabah, which is what he loved.A man had prayed the Asr prayer with him, then passed by some people from the Ansar who were bowing in the Asr prayer facing Bayt al-Maqdis. He said that he bore witness that he had prayed with the Messenger of Allah ﷺ and that he had turned to face the Kaabah. So they shifted their direction while still bowing.

Tirmidhi 340

Sahih

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

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

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

الترمذي 340صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Prayer
Chapter
Beginning of the qibla
Numbering
Darussalam 340
Tirmidhi 340