كتاب الصلاة
4  
The Book of Prayers
(28)
Chapter: Straightening The Rows; The Virtue Of The Front Row And Then The Next; Competing With One Another For The Front Row; The People Of Virtue Should Take Precedence And Be Closest To The Imam
(28)
باب تَسْوِيَةِ الصُّفُوفِ وَإِقَامَتِهَا وَفَضْلِ الأَوَّلِ فَالأَوَّلِ مِنْهَا وَالاِزْدِحَامِ عَلَى الصَّفِّ الأَوَّلِ وَالْمُسَابَقَةِ إِلَيْهَا وَتَقْدِيمِ أُولِي الْفَضْلِ وَتَقْرِيبِهِمْ مِنَ الإِمَامِ
Sahih Muslim 438 b

Abu Sa'id al-Khudri reported:

The Messenger of Allah (ﷺ) saw people at the end of the mosque, and then the (above-mentioned hadith) was narrated.
حَدَّثَنَا عَبْدُ اللَّهِ بْنُ عَبْدِ الرَّحْمَنِ الدَّارِمِيُّ، حَدَّثَنَا مُحَمَّدُ بْنُ عَبْدِ اللَّهِ الرَّقَاشِيُّ، حَدَّثَنَا بِشْرُ بْنُ مَنْصُورٍ، عَنِ الْجُرَيْرِيِّ، عَنْ أَبِي نَضْرَةَ، عَنْ أَبِي سَعِيدٍ الْخُدْرِيِّ، قَالَ رَأَى رَسُولُ اللَّهِ صلى الله عليه وسلم قَوْمًا فِي مُؤَخَّرِ الْمَسْجِدِ ‏.‏ فَذَكَرَ مِثْلَهُ ‏.‏
Reference : Sahih Muslim 438b
In-book reference : Book 4, Hadith 145
USC-MSA web (English) reference : Book 4, Hadith 879
  (deprecated numbering scheme)