Abu Dharr reported,

I asked, "Messenger of Allah, which mosque was the first to be built on earth?"He replied, "The Sacred Mosque."I asked, "Then which?"He replied, "Masjid al-Aqsa."I asked, "How long was the period between them?"He replied, "Forty years. Then wherever the time of prayer overtakes you, pray, for the merit lies therein."In Muslim's wording, "Pray, for it is a mosque."

Azami 3060

Sahih

عن أبي ذر قال

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

الأعظمي 3060صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Mosques
Section
First masjid placed on earth
Numbering
Jami al-Kamil 3060 (2nd edition)
Azami 3060