Sunan an-Nasa'i, Book 4, Hadith 46 (In-Book)

It was narrated from Al-Miqdad bin Al-Aswad thatt 'Ali bin Abi Talib, peace be upon him, told him to ask the Messenger of Allah about a man who gets close to a woman and Madhi comes out of him. (He said: ) "For his daughter is (married) to me and I feel too shy to ask him." So he asked the Messenger of Allah about that and he said: "If any one of you notices that let him sprinkle water on his private parts and perform Wudu' as for prayer."

أَخْبَرَنَا عُتْبَةُ بْنُ عَبْدِ اللَّهِ، قَالَ قُرِئَ عَلَى مَالِكٍ وَأَنَا أَسْمَعُ، عَنْ أَبِي النَّضْرِ، عَنْ سُلَيْمَانَ بْنِ يَسَارٍ، عَنِ الْمِقْدَادِ بْنِ الأَسْوَدِ، عَنْ عَلِيِّ بْنِ أَبِي طَالِبٍ، رضى الله عنه أَمَرَهُ أَنْ يَسْأَلَ رَسُولَ اللَّهِ صلى الله عليه وسلم عَنِ الرَّجُلِ إِذَا دَنَا مِنَ الْمَرْأَةِ فَخَرَجَ مِنْهُ الْمَذْىُ فَإِنَّ عِنْدِي ابْنَتَهُ وَأَنَا أَسْتَحْيِي أَنْ أَسْأَلَهُ ‏.‏ فَسَأَلَ رَسُولَ اللَّهِ صلى الله عليه وسلم عَنْ ذَلِكَ فَقَالَ ‏ "‏ إِذَا وَجَدَ أَحَدُكُمْ ذَلِكَ فَلْيَنْضَحْ فَرْجَهُ وَلْيَتَوَضَّأْ وُضُوءَهُ لِلصَّلاَةِ ‏" ‏ ‏.‏

sunnah.com