A Manhattan judge known for pro-teacher rulings may overturn the firing of a middle-school teacher accused of bedding her 12-year-old student because she says the city did not play fair.

Supreme Court Judge Alice Schlesinger blasted the city Department of Education, saying it apparently used evidence sealed after teacher Claudia Tillery was acquitted in a criminal trial.

“I do agree that a teacher having a relationship with a 12-year-old boy, or a girl, is way, way, way beyond acceptable,” Schlesinger said in a hearing ​last ​week. “But they had no authority to unseal a sealed record.”

Tillery, who taught at MS 35 in Bedford-Stuyvesant, was charged in November 2011 with rape, having repeated sex with a male student in her home and in a motel while plying him with liquor and marijuana and with giving him cash and gifts.

But a Brooklyn jury acquitted Tillery in April 2014 after her two kids and their homeless, schizophrenic father testified in her defense.

A mountain of evidence included the student’s video of Tillery putting her pants on, 8,000 text messages between the two and a DNA analysis finding​ both her and the kid’s saliva on her comforter.

The DOE then used the same evidence against Tillery in a hearing to fire her, calling them “official records.”

Schlesinger called Tillery’s underlying case “egregious and disgusting.” But she added: “It’s clear that no one ever went to court to get an [unsealing] order . . . And it probably would have been denied.”

The city would not say how it obtained the criminal evidence, but Nick Paolucci, a spokesman for the Law Department, insisted, “All the evidence DOE used in its termination proceedings was obtained and used lawfully.”

Helen Peterson, a spokeswoman for the Brooklyn District Attorney’s Office, said, “We did not turn over any sealed trial evidence to anyone. The DOE had its own investigator collecting evidence independently.” An assistant DA testified at the DOE hearing under a subpoena, she added.

Schlesinger, who in 2012 overturned the firing of two female teachers caught trysting in a darkened classroom, has salvaged teachers’ jobs if she found the city violated rules in firing them.

“Alice is not one to let rapists and killers out on the street,” said Betsy Combier, a paralegal who defends accused educators. “But don’t violate procedure in front of her and don’t use information you shouldn’t have had. She’s not going to allow it.”

Schlesinger deferred ​her decision on Tillery until both sides submit additional written arguments.