When the Messenger of Allah ﷺ arrived in Medina, he stayed in the upper part of the city, among a tribe called Banu Amr bin Awf. He remained with them for fourteen nights, then sent for the chiefs of Banu al-Najjar. They came wearing their swords.It is as though I can still see the Messenger of Allah ﷺ on his mount with Abu Bakr riding behind him, and the chiefs of Banu al-Najjar gathered around him, until he dismounted in the courtyard of Abu Ayub.He used to pray wherever the time of prayer found him, and he would pray in the sheep pens. Then he ordered the building of the mosque. He sent for the chiefs of Banu al-Najjar, and when they came he said, "Banu al-Najjar, name me a price for this walled garden of yours."They replied, "No, by Allah, we seek its price from none but Allah."He said, In it was what I shall describe to you. It contained the graves of polytheists, ruins, and date palms. The Messenger of Allah ﷺ ordered that the graves of the polytheists be dug up, the ruins leveled, and the palm trees cut down. They lined up the palm trunks as the qiblah of the mosque and made its doorposts of stone.They began carrying the stones while chanting verses, and the Messenger of Allah ﷺ was with them. They were saying, "O Allah, there is no good except the good of the Hereafter, so grant victory to the Ansar and the Muhajirun."
لما قدم رسول الله ﷺ المدينة، نزل في علو المدينة، في حي يقال لهم بنو عمرو بن عوف، قال: فأقام فيهم أربع عشرة ليلة، ثم أرسل إلى ملأ بني النجار، قال: فجاؤوا متقلدي سيوفهم، قال: وكأني أنظر إلى رسول الله ﷺ على راحلته وأبو بكر ردفه، وملأ بني النجار حوله، حتى ألقى بفناء أبي أيوب، قال: فكان يصلي حيث أدركته الصلاة، ويصلي في مرابض الغنم، قال: ثم أمر ببناء المسجد، فأرسل إلى ملأ بني النجار فجاؤوا، فقال: يا بني النجار، ثامنوني حائطكم هذا، فقالوا: لا والله، لا نطلب ثمنه إلا إلى الله، قال: فكان فيه ما أقول لكم، كانت فيه قبور المشركين، وكانت فيه خرب، وكان فيه نخل، فأمر رسول الله ﷺ بقبور المشركين فنبشت، وبالخرب فسويت، وبالنخل فقطع، قال: فصفوا النخل قبلة المسجد، قال: وجعلوا عضاديته حجارة، قال: جعلوا ينقلون ذاك الصخرة وهم يرتجزون، ورسول الله ﷺ معهم يقولون: اللهم إنه لا خير إلا خير الآخرة، فانصر الأنصار والمهاجره.
Bukhari narrated it in the Book of Merits (3932) and Muslim in the Book of Mosques (524), both from the hadith of Abdul-Warith bin Saeed, from Abu Tayah Yazid bin Humayd Dubi, who said, "Anas bin Malik narrated it to me," and he related it.