‘Umar b. al-Khattab said to the Messenger of Allah (May peace be upon him) that he became sexually defiled at night (asking him what he should do). The Messenger of Allah (May peace be upon him) said : You should perform ablution and wash your penis and then sleep. (Using translation from Abū Dāʾūd 221)
أَنَّهُ ذَكَرَ عُمَرُ بْنُ الْخَطَّابِ لِرَسُولِ اللهِ ﷺأَنَّهُ تُصِيبُهُ جَنَابَةٌ مِنَ اللَّيْلِ فَقَالَ لَهُ رَسُولُ اللهِ ﷺ تَوَضَّأْ وَاغْسِلْ ذَكَرَكَ ثُمَّ نَمْ