Bara bin Azib reported,

When the Messenger of Allah ﷺ first arrived in Medina, he stayed with his maternal relatives among the Ansar. He prayed facing Bayt al-Maqdis for sixteen or seventeen months, but he wished that his prayer direction would be toward the Kabah.The first prayer he prayed facing the Kabah was the afternoon prayer, and a group of people prayed it with him. One of those who had prayed with him went out and passed by the people of a mosque while they were bowing in prayer. He said, "I swear by Allah, I have just prayed with the Messenger of Allah ﷺ facing Mecca." So they turned, just as they were, to face the Kabah.He was pleased to have the prayer direction changed to the Kabah. The Jews and the People of the Book had been pleased when he prayed facing Bayt al-Maqdis, but when he turned his face toward the Kabah, they rejected this.

Ahmad 18496

Sahih

حدثنا حسن بن موسى حدثنا زهير حدثنا أبو إسحاق

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

أن رسول الله ﷺ كان أول ما قدم المدينة نزل على أجداده وأخواله من الأنصار وأنه صلى قبل بيت المقدس ستة عشر أو سبعة عشر شهرا وكان يعجبه أن تكون قبلته قبل البيت وأنه صلى أول صلاة صلاها صلاة العصر وصلى معه قوم فخرج رجل ممن صلى معه فمر على أهل مسجد وهم راكعون فقال أشهد بالله لقد صليت مع رسول الله ﷺ قبل مكة قال فداروا كما هم قبل البيت وكان يعجبه أن يحول قبل البيت وكان اليهود قد أعجبهم إذ كان يصلي قبل بيت المقدس وأهل الكتاب فلما ولى وجهه قبل البيت أنكروا ذلك

أحمد 18496صحيح
Contents
Reference
Commentary
Ayat
Collection
Musnad Ahmad
Book
Bara bin Azib
Numbering
Darussalam 18496
Ahmad 18496