Sahih al-Bukhari 67:4
Narrated `Abdullah:
We were with the Prophet (ﷺ) while we were young and had no wealth. So Allah's Messenger (ﷺ) said, "O young people! Whoever among you can marry, should marry, because it helps him lower his gaze and guard his modesty (i.e. his private parts from committing illegal sexual intercourse etc.), and whoever is not able to marry, should fast, as fasting diminishes his sexual power."
Reference
Sahih al-Bukhari 67:4
In-book reference
Book 67, Hadith 4
Arabic Text
حَدَّثَنَا عُمَرُ بْنُ حَفْصِ بْنِ غِيَاثٍ، حَدَّثَنَا أَبِي، حَدَّثَنَا الأَعْمَشُ، قَالَ حَدَّثَنِي عُمَارَةُ، عَنْ عَبْدِ الرَّحْمَنِ بْنِ يَزِيدَ، قَالَ دَخَلْتُ مَعَ عَلْقَمَةَ وَالأَسْوَدِ عَلَى عَبْدِ اللَّهِ فَقَالَ عَبْدُ اللَّهِ كُنَّا مَعَ النَّبِيِّ صلى الله عليه وسلم شَبَابًا لاَ نَجِدُ شَيْئًا فَقَالَ لَنَا رَسُولُ اللَّهُ صلى الله عليه وسلم " يَا مَعْشَرَ الشَّبَابِ مَنِ اسْتَطَاعَ الْبَاءَةَ فَلْيَتَزَوَّجْ، فَإِنَّهُ أَغَضُّ لِلْبَصَرِ، وَأَحْصَنُ لِلْفَرْجِ، وَمَنْ لَمْ يَسْتَطِعْ فَعَلَيْهِ بِالصَّوْمِ، فَإِنَّهُ لَهُ وِجَاءٌ ".