A married Queens teacher and dad who repeatedly had sex with a 13-year-old girl in his family’s home openly made out with his lawyer wife in court yesterday — minutes before landing a sweetheart jail deal for his rape charge.

As a Queens judge dispensed criminal cases feet away, Daniel Reilly, 36, shared long, passionate kisses with wife Annemarie, 28, who rubbed his knee and held his hand as they sat in the courtroom’s fourth row.

Reilly — who has a 1-year-old daughter with his wife — had sex with his sixth-grade student in his and his wife’s bed at their Forest Hills home at least a dozen times while his family was out, authorities have said.

The teacher had pursued the child until she finally agreed to the sick affair, and he used code names to hide their trysts for at least seven months beginning in August, officials said.

The IS 237 English teacher, who resigned last week, pleaded guilty yesterday to felony second-degree rape for the affair, a crime that can carry a sentence of up to seven years behind bars.

But under a deal designed at least partly to spare his young victim a trial, Reilly received just four months’ prison, plus 10 years’ probation.

He also must attend 104 sex-offender classes, and his teacher’s license was revoked.

“Like other politicians and public figures, he strayed and only thought with the lower half of his body. It was a mistake,” one of the ex-Marine’s two lawyers, Eric Franz, said afterward.