The Messenger of Allah ﷺ said, "The angels say, 'Lord, that servant of Yours intends to commit a sin,' though He sees him better than they do. He says, 'Watch over him. If he commits it, record it against him as one sin, and if he abstains from it, record it for him as a good deed, for he abstained from it only for My sake.'"
قال رسول الله ﷺ: قالت الملائكة: رب ذاك عبدك يريد أن يعمل سيئة- وهو أبصر به-، فقال: ارقبوه. فإن عملها فاكتبوها له بمثلها، وإن تركها فاكتبوها له حسنة إنما تركها من جراي.
Muslim narrated it in the Book of Faith (129) through the route of Abdul-Razzaq, who reported from Maamar, from Hammam bin Munabbih, who said, "This is what Abu Hurairah told us, from the Messenger of Allahﷺ." He then mentioned several hadiths, among them this one.