As long as the kids are away, teachers can play, a panel of judges said Thursday, ruling that educators shouldn’t be fired for having sex with one another — even in their classrooms.

The Manhattan appellate judges said foreign-language teachers Alini Brito, 34, and Cindy Mauro, 38, were treated too harshly when they were dismissed for engaging in a topless classroom tryst inside Brooklyn’s James Madison HS in 2009.

“The penalty of termination is shockingly disproportionate,” said the ruling, which noted that “engagement in what appeared to be consensual sexual conduct with an adult colleague is not in and of itself criminal or otherwise improper.”

And at least the school-room romp didn’t involve minors, the Appellate Division judges added.

“Indeed, lesser penalties have been imposed where a teacher had an ongoing relationship or engaged in inappropriate behavior with a student,” the decision says.

The ruling stunned fellow teachers, who feared the judges have given a green light to all sorts of kinky classroom sleaze.

“[It] sets a poor example for other teachers. They may think they can do it, too,” fumed one James Madison teacher, who asked not to be named.

The ruling also shocked students at the school, which became known as “Horndog High” after news spread of Brito and Mauro’s canoodling. “A student could have walked in on them,” said 10th-grader Tiffany Kagan.

“Things like that shouldn’t be done in the classroom. Couldn’t they have waited until they got home?”

The judges, however, noted that no kids actually saw the two hooking up.

In deciding to go easy on the teachers, the judge gave them credit because their gropefest happened while they were at the school after hours to attend a musical competition on Nov. 20, 2009, “although [they] were not required to do so.”

Apparently the student musical was kind of a snooze. The duo snuck away from the festivities to a third-floor classroom, where the “partially undressed” romance-language teachers were caught making out by school safety agents.

They were soon fired. But in 2012, a lower court judge ruled the women were due a second administrative hearing.

The higher court on Thursday said the women only deserve a slap on the wrist. They ordered the DOE to impose a “lesser penalty” than firing.

The Department of Education is “disappointed with the decision,” a spokesman said. Senior city attorney Suzanne Colt said she is reviewing the ruling and “considering our options.”

The ousted teachers could not be reached for comment.

Additional reporting by Jennifer Bain and Yoav Gonen