Sayyiduna Abu Sa'id al-Khudri (may Allah be pleased with him) says that garlic, onions and leeks were mentioned in the presence of the Messenger of Allah (peace and blessings be upon him). It was said: O Messenger of Allah, of these the one you dislike most is garlic; do you declare it unlawful? He (peace and blessings be upon him) said: "No, eat it; but whoever eats it, let him not come near this mosque until its smell has gone."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 5059