It is narrated from Sayyiduna Abdullah bin Amir bin Rabi'ah (may Allah be pleased with them both) from his father that once darkness came over us (night fell) while we were on a journey. The qiblah became unclear to us, and each one of us prayed according to his own estimate. When the sky cleared, it turned out that some of us had prayed facing other than the qiblah. We mentioned this to the Messenger of Allah (peace and blessings be upon him), and he (peace and blessings be upon him) said: "Your prayer is valid." And this verse was revealed:
"Wherever you turn, there is the Face of Allah" [Surah al-Baqarah: 115].
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2241