All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
If intercourse takes place before the Athaan (call for prayer) and ends before it, then there is no problem and the fasting is valid. In the case that intercourse takes place during the Athaan and he knows of it, then he does not have to make up (the fast) nor offer expiation if he withdraws immediately (i.e., terminates the intercourse). If he continues, it is due upon him to make up the fast (for this day) and offer expiation. If this occurs after the Athaan while thinking that it has yet to come and he then finds that it was after the Athaan and the time of prayer, then the fasting is invalid and both of them should make up for this day. Expiation is due upon him if he continues after knowing that the call for Al-Fajr prayer was made because he violated the sanctity of this month by continuing. So, along with making it up, he should also offer expiation. If he stopped upon knowing that the Athaan passed, he does not have to offer expiation but he should make up for this day as mentioned above. The woman is like the man in all these cases if she does it willingly.
An-Nawawi said, "If dawn rises while one is having intercourse with his wife and he comes to know but continues having intercourse, his fast is invalidated with no difference of opinion among scholars." He said, "There is no known difference among scholars concerning this matter. He should offer expiation according to this school of Fiqh (i.e., the Shaafi'i school)."
An-Nawawi also said about the issue of the one who engages in intercourse while thinking that dawn has not yet risen but found the opposite to be true: "If he eats, drinks or engages in intercourse while thinking that the sun has set or that the dawn had not yet broken but then the opposite was discovered, then we have already mentioned that he should make up for this…. This is the opinion adopted by Abu Haneefah, Maalik, Ahmad, Abu Thawr and the majority of the scholars ."
Allaah Knows best.