It is narrated from Sayyiduna Ibn Mas'ud (may Allah be pleased with him) that once a man said to the Prophet (peace and blessings be upon him) that he encountered a woman in one of the gardens of Madinah and did everything with her except intercourse. Upon this, Allah revealed this verse: «﴿وَأَقِمِالصَّلَاةَطَرَفَيِالنَّهَارِوَزُلَفًامِنَاللَّيْلِإِنَّالْحَسَنَاتِيُذْهِبْنَالسَّيِّئَاتِ﴾»[هود : 114] "Establish prayer at the two ends of the day and at some hours of the night. Indeed, good deeds erase bad deeds."
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 4325
Hadith Gradingحکم دارالسلام:حديث صحيح، م: 2763، وهذا إسناد حسن من أجل سماك.