Abu Dharr reported,

I asked, "Messenger of Allah, which mosque was first established on earth?"He replied, "The Sacred Mosque."I asked, "Then which?"He said, "Masjid al-Aqsa."I asked, "How long was the period between them?"He answered, "Forty years. Then wherever the time of prayer overtakes you after that, pray there, for the merit lies in it."

Azami 10608

Sahih

عن أبي ذر قال

قلت يا رسول الله أي مسجد وضع في الأرض أول؟ قال: المسجد الحرام، قال: قلت: ثم أي؟ قال: المسجد الأقصى، قلت: كم بينهما؟ قال: أربعون سنة، ثم أينما أدركتك الصلاة بعد فصله، فإن الفضل فيه.

الأعظمي 10608صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Virtues of the lands
Chapter
Virtue of Makkah and reports about it
Section
Masjid al-Haram was the first masjid established on earth for the worship of Allah Most High
Numbering
Jami al-Kamil 10608 (2nd edition)
Azami 10608