Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bayhaqi:2241Abū Bakr Muḥammad b. al-Ḥusayn b. Fūrak > ʿAbdullāh b. Jaʿfar b. Aḥmad > Yūnus b. Ḥabīb > Abū Dāwud al-Ṭayālisī > al-Ashʿath b. Saʿīd Abū al-Rabīʿ And ʿUmar b. Qays > ʿĀṣim b. ʿUbaydullāh > ʿAbdullāh b. ʿĀmir b. Rabīʿah from his father

[Machine] Once, while we were traveling, darkness overtook us and the direction of the Qibla became unclear to us. Each of us prayed according to his own judgment. When it became clear, some of us had prayed in a direction other than the Qibla, while others had prayed towards the Qibla. We then mentioned this to the Messenger of Allah ﷺ , and he said, "Your prayers have passed and been accepted, for Allah says, 'And to Allah belongs the east and the west. So wherever you turn, there is the face of Allah.'" (Quran 2:115)  

البيهقي:٢٢٤١أَخْبَرَنَا أَبُو بَكْرٍ مُحَمَّدُ بْنُ الْحُسَيْنِ بْنِ فُورَكٍ أنبأ عَبْدُ اللهِ بْنُ جَعْفَرِ بْنِ أَحْمَدَ ثنا يُونُسُ بْنُ حَبِيبٍ ثنا أَبُو دَاوُدَ الطَّيَالِسِيُّ ثنا الْأَشْعَثُ بْنُ سَعِيدٍ أَبُو الرَّبِيعِ وَعُمَرُ بْنُ قَيْسٍ قَالَا ثنا عَاصِمُ بْنُ عُبَيْدِ اللهِ عَنْ عَبْدِ اللهِ بْنِ عَامِرِ بْنِ رَبِيعَةَ عَنْ أَبِيهِ قَالَ

أُظْلِمَتْ مَرَّةً وَنَحْنُ فِي سَفَرٍ وَاشْتَبَهَتْ عَلَيْنَا الْقِبْلَةُ فَصَلَّى كُلُّ رَجُلٍ مِنَّا حِيَالَهُ فَلَمَّا انْجَلَتْ إِذَا بَعْضُنَا صَلَّى لِغَيْرِ الْقِبْلَةِ وَبَعْضُنَا قَدْ صَلَّى لِلْقِبْلَةِ فَذَكَرْنَا ذَلِكَ لِرَسُولِ اللهِ ﷺ فَقَالَ مَضَتْ صَلَاتُكُمْ وَنَزَلَتْ {فَأَيْنَمَا تُوَلُّوا فَثَمَّ وَجْهُ اللهِ} [البقرة 115]  


See similar narrations below:

Collected by Ibn Mājah
ibnmajah:1020Yaḥyá b. Ḥakīm > Abū Dāwud > Ashʿath b. Saʿīd Abū al-Rabīʿ al-Sammān > ʿĀṣim b. ʿUbaydullāh > ʿAbdullāh b. ʿĀmir b. Rabīʿah from his father

“We were with the Messenger of Allah ﷺ on a journey, and the sky was overcast so it was difficult for us to determine the Qiblah. So we performed prayer, and we marked the location.* Later, when the sun reappeared, we realized that we had prayed facing a direction other than the Qiblah. We mentioned that to the Prophet ﷺ, then the Words were revealed: ‘So wherever you turn there is the Face of Allah.’” [2:115]  

ابن ماجة:١٠٢٠حَدَّثَنَا يَحْيَى بْنُ حَكِيمٍ حَدَّثَنَا أَبُو دَاوُدَ حَدَّثَنَا أَشْعَثُ بْنُ سَعِيدٍ أَبُو الرَّبِيعِ السَّمَّانُ عَنْ عَاصِمِ بْنِ عُبَيْدِ اللَّهِ عَنْ عَبْدِ اللَّهِ بْنِ عَامِرِ بْنِ رَبِيعَةَ عَنْ أَبِيهِ قَالَ

كُنَّا مَعَ رَسُولِ اللَّهِ ﷺ فِي سَفَرٍ فَتَغَيَّمَتِ السَّمَاءُ وَأَشْكَلَتْ عَلَيْنَا الْقِبْلَةُ فَصَلَّيْنَا وَأَعْلَمْنَا فَلَمَّا طَلَعَتِ الشَّمْسُ إِذَا نَحْنُ قَدْ صَلَّيْنَا لِغَيْرِ الْقِبْلَةِ فَذَكَرْنَا ذَلِكَ لِلنَّبِيِّ ﷺ فَأَنْزَلَ اللَّهُ {فَأَيْنَمَا تُوَلُّوا فَثَمَّ وَجْهُ اللَّهِ}