We were with the Messenger of Allah ﷺ in a gathering when he said, "Pledge allegiance to me that you will not associate anything with Allah, that you will not commit adultery, that you will not steal, and that you will not kill a soul whom Allah has forbidden to be killed except by right. Whoever among you fulfills this, his reward is with Allah. Whoever commits any of these offenses and is punished for it, that punishment is an expiation for him. And whoever commits any of these offenses and Allah conceals it for him, his affair is left to Allah. If He wishes, He will pardon him, and if He wishes, He will punish him."
كنا مع رسول الله ﷺ في مجلس فقال: تبايعوني على أن لا تشركوا بالله شيئا، ولا تزنوا، ولا تسرقوا، ولا تقتلوا النفس التي حرم الله إلا بالحق. فمن وفى منكم فأجره على الله، ومن أصاب شيئا من ذلك فعوقب به، فهو كفارة له، ومن أصاب شيئا من ذلك، فستر الله عليه فأمره إلى الله، إن شاء عفا عنه، وإن شاء عذبه.
Bukhari narrated it in Hudud (6784) and Muslim in Hudud (1709/41), both from the hadith of Sufyan bin Uyayna, from Zuhri, from Abu Idris, from Ubada bin Samit, who related it. The wording given is Muslim's.