Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
bukhari:293Musaddad > Yaḥyá > Hishām b. ʿUrwah from my father > Abū Ayyūb > Ubay b. Kaʿb

I asked Messenger of Allah ﷺ about a man who engages in sexual intercourse with his wife but does not discharge. He replied, "He should wash the parts which comes in contact with the private parts of the woman, perform ablution and then pray." (Abu ʿAbdullah said, "Taking a bath is safer and is the last order.")  

البخاري:٢٩٣حَدَّثَنَا مُسَدَّدٌ حَدَّثَنَا يَحْيَى عَنْ هِشَامِ بْنِ عُرْوَةَ قَالَ أَخْبَرَنِي أَبِي قَالَ أَخْبَرَنِي أَبُو أَيُّوبَ قَالَ أَخْبَرَنِي أُبَىُّ بْنُ كَعْبٍ

أَنَّهُ قَالَ يَا رَسُولَ اللَّهِ إِذَا جَامَعَ الرَّجُلُ الْمَرْأَةَ فَلَمْ يُنْزِلْ قَالَ يَغْسِلُ مَا مَسَّ الْمَرْأَةَ مِنْهُ ثُمَّ يَتَوَضَّأُ وَيُصَلِّي قَالَ أَبُو عَبْدِ اللَّهِ الْغَسْلُ أَحْوَطُ وَذَاكَ الآخِرُ وَإِنَّمَا بَيَّنَّا لاِخْتِلاَفِهِمْ  


See similar narrations below:

Collected by Bayhaqī
bayhaqi:770Muḥammad b. ʿAbdullāh al-Ḥāfiẓ > Abū Bakr b. Isḥāq al-Faqīh > Abū al-Muthanná > Musaddad > Yaḥyá b. Saʿīd > Hishām b. ʿUrwah from my father > Abū Ayyūb > Ubay b. Kaʿb

[Machine] He said, "O Messenger of Allah, if a man has sexual intercourse with a woman but does not ejaculate, he said: he should wash what has been touched by the woman, then he should perform ablution and offer prayer."  

البيهقي:٧٧٠وَأَمَّا الْحَدِيثُ الَّذِي أَخْبَرَنَا مُحَمَّدُ بْنُ عَبْدِ اللهِ الْحَافِظُ أنا أَبُو بَكْرِ بْنُ إِسْحَاقَ الْفَقِيهُ ثنا أَبُو الْمُثَنَّى ثنا مُسَدَّدٌ ثنا يَحْيَى بْنُ سَعِيدٍ عَنْ هِشَامِ بْنِ عُرْوَةَ قَالَ أَخْبَرَنِي أَبِي قَالَ أَخْبَرَنِي أَبُو أَيُّوبَ قَالَ أَخْبَرَنِي أُبَيُّ بْنُ كَعْبٍ

أَنَّهُ قَالَ يَا رَسُولَ اللهِ إِذَا جَامَعَ الرَّجُلُ الْمَرْأَةَ فَلَمْ يُنْزِلْ قَالَ يَغْسِلُ مَا مَسَّ الْمَرْأَةَ مِنْهُ ثُمَّ يَتَوَضَّأُ وَيُصَلِّي  

رَوَاهُ الْبُخَارِيُّ فِي الصَّحِيحِ عَنْ مُسَدَّدٍ وَرَوَاهُ مُسْلِمٌ مِنْ أَوْجُهٍ أُخَرَ عَنْ هِشَامٍ