It is narrated from Ubayy bin Ka'b (may Allah be pleased with him), he states: I asked, "O Messenger of Allah (ﷺ)! When one of us has intercourse and withdraws before ejaculation, what should he do?" The Prophet (ﷺ) said: "He should wash the part that touched the woman, then perform ablution and then offer prayer."
Hadith Referenceمسند الإمام الشافعي / كتاب الطهارة / 99
Hadith Takhrijاخرجہ البخاری: الغسل، باب غسل ما يصيب من رطوبة فرج المرأة: (293) ومسلم، الحيض، باب بيان أن الجماع كان في اول الاسلام لا يوجب الغسل الا ان ينزل المني (346)