كتاب الحج
15  
The Book of Pilgrimage
(88)
Chapter: Al-Madinah eliminates its Dross and it is also called Tabah, and Taibah
(88)
باب الْمَدِينَةِ تَنْفِي شِرَارَهَا ‏‏
Sahih Muslim 1381

Abu Huraira (Allah be pleased with him) reported Allah's Messenger (ﷺ) as saying:

A time will come for the people (of Medina) when a man will invite his cousin and any other near relation: Come (and settle) at (a place) where living is cheap, come to where there is plenty, but Medina will be better for them; would they know it! By Him in Whose Hand is my life, none amongst them would go out (of the city) with a dislike for it, but Allah would make his successor in it someone better than be. Behold. Medina is like furnace which eliminates from it the impurities. And the Last Hour will not come until Medina banishes its evils just as a furnace eliminates the impurities of iron.
حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا عَبْدُ الْعَزِيزِ، - يَعْنِي الدَّرَاوَرْدِيَّ - عَنِ الْعَلاَءِ، عَنْ أَبِيهِ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ ‏ "‏ يَأْتِي عَلَى النَّاسِ زَمَانٌ يَدْعُو الرَّجُلُ ابْنَ عَمِّهِ وَقَرِيبَهُ هَلُمَّ إِلَى الرَّخَاءِ هَلُمَّ إِلَى الرَّخَاءِ وَالْمَدِينَةُ خَيْرٌ لَهُمْ لَوْ كَانُوا يَعْلَمُونَ وَالَّذِي نَفْسِي بِيَدِهِ لاَ يَخْرُجُ مِنْهُمْ أَحَدٌ رَغْبَةً عَنْهَا إِلاَّ أَخْلَفَ اللَّهُ فِيهَا خَيْرًا مِنْهُ أَلاَ إِنَّ الْمَدِينَةَ كَالْكِيرِ تُخْرِجُ الْخَبِيثَ ‏.‏ لاَ تَقُومُ السَّاعَةُ حَتَّى تَنْفِيَ الْمَدِينَةُ شِرَارَهَا كَمَا يَنْفِي الْكِيرُ خَبَثَ الْحَدِيدِ ‏"‏ ‏.‏
Reference : Sahih Muslim 1381
In-book reference : Book 15, Hadith 556
USC-MSA web (English) reference : Book 7, Hadith 3188
  (deprecated numbering scheme)