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

It wasnarrated that Bara’ said: “We prayed with the Messenger ofAllah(PBUH) facing towards Baitul-Maqdis (Jerusalem) for eighteenmonths,then the Qiblah was changed to the Ka’bah two months after theProphet (PBUH) entered Al-Madinah. When the Messenger of Allah (PBUH)prayed towards Baitul-Maqdis, he would often lift his face towardstheheavens, and Allah knew what was in the heart of His Prophet andhowhe longed to face the Ka’bah (during prayer). Jibril appeared(in thesky), and the Messenger of Allah (PBUH) started watching himas he wasdescending between the heavens and the earth, waiting tosee what hewould bring. Then Allah revealed the words: ‘Verily, Wehave seen theturning of your face towards the heaven. Surely, Weshall turn you toa Qiblah that shall please you, so turn your facein the direction ofAl-Masjid Al-Haram (at Makkah). And wherever youpeople are, turn yourfaces (during prayer) in that direction.’[2:144] Then someone came tous and said: ‘The Qiblah has beenchanged to the Ka’bah.’ We hadperformed two Rak’ah facingtowards Jerusalem. And we were bowing. Sowe turned around, and wecontinued our prayer. The Messenger of Allah(PBUH) said: ‘O Jibril!What about our prayer facing towards Baitul-Maqdis?’ Then Allahrevealed the words: “And Allah would never makeyour faith to belost.” [2:143] Translation Not Available

Book Ref: Sunan Ibn Majah Book 5 Hadith 1010
Web Ref:  Sunan Ibn Majah Vol 1 Book 5 Hadith 1010