On the authority of Abu Hurayrah (may Allah be pleased with him) that the Prophet (PBUH), from among the things he reports from his Lord (mighty and sublime be He), is that he said: A servant [of Allah's] committed a sin and said: O Allah, forgive me my sin. And He (glorified and exalted be He) said: My servant has committed a sin and has known that he has a Lord who forgives sins and punishes for them. Then he sinned again and said: O Lord, forgive me my sin. And He (glorified and exalted be He) said: My servant has committed a sin and has known that he has a Lord who forgives sins and punishes for them. Then he sinned again and said: O Lord, forgive me my sin. And He (glorified and exalted be He) said: My servant has committed a sin and has known that he has a Lord who forgives sins and punishes for sins. Do what you wish, for I have forgiven you.
It was related by Muslim (also by al-Bukhari).