Sunan Ibn Majah, Volume 2, Book 5, Hadith 1010 (DarusSalam)

It was narrated that Bara’ said: “We prayed with the Messenger of Allah facing towards Baitul-Maqdis (Jerusalem) for eighteen months, then the Qiblah was changed to the Ka’bah two months after the Prophet entered Al-Madinah. When the Messenger of Allah prayed towards Baitul-Maqdis, he would often lift his face towards the heavens, and Allah knew what was in the heart of His Prophet and how he longed to face the Ka’bah (during prayer). Jibril appeared (in the sky), and the Messenger of Allah started watching him as he was descending between the heavens and the earth, waiting to see what he would bring. Then Allah revealed the words: ‘Verily, We have seen the turning of your face towards the heaven. Surely, We shall turn you to a Qiblah that shall please you, so turn your face in the direction of Al-Masjid Al-Haram (at Makkah). And wherever you people are, turn your faces (during prayer) in that direction.’ [2:144] Then someone came to us and said: ‘The Qiblah has been changed to the Ka’bah.’ We had performed two Rak’ah facing towards Jerusalem. And we were bowing. So we turned around, and we continued our prayer. The Messenger of Allah said: ‘O Jibril! What about our prayer facing towards Baitul- Maqdis?’ Then Allah revealed the words: “And Allah would never make your faith to be lost.” [2:143]

حَدَّثَنَا عَلْقَمَةُ بْنُ عَمْرٍو الدَّارِمِيُّ، حَدَّثَنَا أَبُو بَكْرِ بْنُ عَيَّاشٍ، عَنْ أَبِي إِسْحَاقَ، عَنِ الْبَرَاءِ، قَالَ صَلَّيْنَا مَعَ رَسُولِ اللَّهِ ـ صلى الله عليه وسلم ـ نَحْوَ بَيْتِ الْمَقْدِسِ ثَمَانِيَةَ عَشَرَ شَهْرًا وَصُرِفَتِ الْقِبْلَةُ إِلَى الْكَعْبَةِ بَعْدَ دُخُولِهِ إِلَى الْمَدِينَةِ بِشَهْرَيْنِ وَكَانَ رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ إِذَا صَلَّى إِلَى بَيْتِ الْمَقْدِسِ أَكْثَرَ تَقَلُّبَ وَجْهِهِ فِي السَّمَاءِ وَعَلِمَ اللَّهُ مِنْ قَلْبِ نَبِيِّهِ ـ صلى الله عليه وسلم ـ أَنَّهُ يَهْوَى الْكَعْبَةَ فَصَعِدَ جِبْرِيلُ فَجَعَلَ رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ يُتْبِعُهُ بَصَرَهُ وَهُوَ يَصْعَدُ بَيْنَ السَّمَاءِ وَالأَرْضِ يَنْظُرُ مَا يَأْتِيهِ بِهِ فَأَنْزَلَ اللَّهُ ‏{قَدْ نَرَى تَقَلُّبَ وَجْهِكَ فِي السَّمَاءِ}‏ الآيَةَ فَأَتَانَا آتٍ فَقَالَ إِنَّ الْقِبْلَةَ قَدْ صُرِفَتْ إِلَى الْكَعْبَةِ وَقَدْ صَلَّيْنَا رَكْعَتَيْنِ إِلَى بَيْتِ الْمَقْدِسِ وَنَحْنُ رُكُوعٌ فَتَحَوَّلْنَا فَبَنَيْنَا عَلَى مَا مَضَى مِنْ صَلاَتِنَا فَقَالَ رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ ‏"‏ يَا جِبْرِيلُ كَيْفَ حَالُنَا فِي صَلاَتِنَا إِلَى بَيْتِ الْمَقْدِسِ ‏"‏ ‏.‏ فَأَنْزَلَ اللَّهُ عَزَّ وَجَلَّ ‏{وَمَا كَانَ اللَّهُ لِيُضِيعَ إِيمَانَكُمْ}‏ ‏.‏

sunnah.com