Abdullah bin Masud reported,

A man kissed a woman, then came to the Messenger of Allah ﷺ and told him about it.He said, then was revealed, "And establish prayer at the two ends of the day and at the approach of the night. Indeed, good deeds drive away bad deeds. That is a reminder for those who remember" [Hud 11:114].The man asked, "Is this for me alone, Messenger of Allah?"He replied, "It is for whoever among my community acts upon it."In another wording, a man came to the Prophet ﷺ and mentioned that he had taken from a woman either a kiss, a touch with the hand, or something of the sort, as if asking about its expiation. So Allah عز وجل revealed, and he then mentioned the same.In a third wording, a man committed something short of fornication with a woman, so he went to Umar bin Khattab, who made the matter seem grave to him. Then he went to Abu Bakr, who also made it seem grave. Then he went to the Prophet ﷺ, and he mentioned the same.

Azami 11391

Sahih

عن عبد الله بن مسعود

أن رجلا أصاب من امرأة قبلة، فأتى رسول الله ﷺ فذكر ذلك له، قال: فأنزلت: {وأقم الصلوة طرف النهار وزلفا من اليل إن الحسنت يذهبن السيئات ذلك ذكرى للذاكرين} [سورة هود: ١١٤] قال: فقال الرجل: ألي هذه يا رسول الله؟ قال: لمن عمل بها من أمتي. وفي لفظ عنه: أن رجلا أتى النبي ﷺ، فذكر أنه أصاب من امرأة إما قبلة، أو مسا بيد أو شيئا، كأنه يسأل عن كفارتها، قال: فأنزل الله عز وجل، ثم ذكر مثله. وفي لفظ ثالث عنه: أصاب رجل من امرأة شيئا دون الفاحشة، فأتى عمر بن الخطاب فعظم عليه، ثم أتى أبا بكر فعظم عليه، ثم أتى النبي ﷺ ثم ذكر مثله.

الأعظمي 11391صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Repentance and seeking forgiveness
Chapter
Comprehensive and general supplications
Section
Indeed good deeds remove bad deeds
Numbering
Jami al-Kamil 11391 (2nd edition)
Azami 11391