Abdullah bin Mirdas (may Allah have mercy on him) said: A man from the neighbourhood came to me and said: I passed by my wife in the moonlight and she pleased me, so I had intercourse with her during the month of Ramadan, then I slept until morning came. I said: Go to Abdullah bin Mas'ud or Abu Hakim al-Muzani. And (there) was Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him), so I asked him, saying: I was in a state of major ritual impurity (janabah) (should I fast)? He said: "You were in janabah, so the prayer was not permitted for you; then you took a ritual bath (ghusl), so the prayer became permitted for you, and fasting also became permitted for you, so fast."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 9531