It was narrated from ‘Abdullah bin Mas’ud that a man did something with a woman that was less than adultery; I do not know how far it went, but it was less than adultery. He went to the Prophet (ﷺ) and told him about that. Then Allah revealed the words:
“And perform the prayer, at the two ends of the day and in some hours of the night. Verily, the good deeds remove the evil deeds. That is a reminder for the mindful.” [11:114] He said: “O Messenger of Allah, is this only for me?” He said: “It is for everyone who acts upon it.”
حَدَّثَنَا سُفْيَانُ بْنُ وَكِيعٍ، حَدَّثَنَا إِسْمَاعِيلُ ابْنُ عُلَيَّةَ، عَنْ سُلَيْمَانَ التَّيْمِيِّ، عَنْ أَبِي عُثْمَانَ النَّهْدِيِّ، عَنْ عَبْدِ اللَّهِ بْنِ مَسْعُودٍ، أَنَّ رَجُلاً، أَصَابَ مِنِ امْرَأَةٍ يَعْنِي مَا دُونَ الْفَاحِشَةِ فَلاَ أَدْرِي مَا بَلَغَ غَيْرَ أَنَّهُ دُونَ الزِّنَا فَأَتَى النَّبِيَّ ـ صلى الله عليه وسلم ـ فَذَكَرَ ذَلِكَ لَهُ فَأَنْزَلَ اللَّهُ سُبْحَانَهُ ‏{أَقِمِ الصَّلاَةَ طَرَفَىِ النَّهَارِ وَزُلَفًا مِنَ اللَّيْلِ إِنَّ الْحَسَنَاتِ يُذْهِبْنَ السَّيِّئَاتِ ذَلِكَ ذِكْرَى لِلذَّاكِرِينَ}‏ فَقَالَ يَا رَسُولَ اللَّهِ أَلِي هَذِهِ قَالَ ‏ "‏ لِمَنْ أَخَذَ بِهَا ‏"‏ ‏.‏
GradeSahih (Darussalam)
English reference : Vol. 1, Book 5, Hadith 1398
Arabic reference : Book 5, Hadith 1462