It is narrated from Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) that once the people were offering the dawn prayer in the Masjid of Quba when someone came to them and said: "Last night Qur'an was revealed to the Messenger of Allah (peace and blessings be upon him), and he (peace and blessings be upon him) has been commanded to pray facing the Ka'bah." (Hearing this,) they turned their faces (while still in prayer) towards the Ka'bah, whereas their faces had been towards Sham; then they swung round towards the Ka'bah.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 2189