A report in weekly magazine Der Spiegel said the relationship developed after the girl wrote the 46-year-old father a note saying "I love you."
The maths and biology teacher claimed on Thursday that it was not the first time that a pupil had fallen in love with him, though he normally ignored them. He told the court that the girl in question had waited for him outside the teacher's room at "almost every break."
He testified that she sent him an invitation on Facebook in the autumn of 2010, after which they spent three hours a day chatting on the social network site.
He said he refused an invitation to go to the cinema in December 2010, but then agreed to meet up with her a few weeks later. The sexual relationship began in February 2011.
The affair was revealed when the victim's sister accidentally logged into her Facebook account and read her correspondence with the teacher. She and their mother then alerted the police.
The teacher was suspended, but continued to meet the girl. He admitted in court that he should have sought help.
A verdict is expected on April 13.