A Queens gym teacher ​charged with rape for allegedly carrying on ​​a ​sexual relationship with a ​16-year-old student flipped out when she learned he was taking another girl to the prom, prosecutors ​revealed in court Tuesday.

Joy Morsi, 38, ​a Grover Cleveland High School teacher​, was charged with 20 counts each of third-degree rape and criminal sexual act for her​ alleged​ fling with the minor.

Morsi, a wife and mother from Massapequa, LI, was also charged with endangering the welfare of a child, and faces up to four years in prison if convicted, said Queens DA Richard Brown.

The affair ended a few weeks ago, when Morsi got “jealous” that her boy toy took a girl to the prom, Prosecutor Taylor Piscionere said at the teacher’s arraignment.

A second student has since come forward to say he also had sex with the teacher, sources told The Post.

“This defendant violated the teacher-student trust,” Piscionere said in court, where Morsi’s dejected husband looked on.

Prosecutors said Morsi, who has since been suspended by the Education Department, befriended ​the boy, a wrestler at the Ridgewood school​,​ when he needed help losing weight to make the school’s wrestling team.

Morsi, in an email, allegedly asked the student if he was a virgin, and he replied that he was.

Their relationship escalated and got physical on June 5, 2013, when Morsi brought the teen into a closet in the school’s gym, exposed her breast to him, performed oral sex and had intercourse, according to court documents.

Prosecutors said the teacher and student had sex more than 20 times in the school last year in various places, including the basement and gymnasium, prosecutors said.

Morsi took their sexual escapades outside of the school to various deserted parking lots and sent him raunchy selfies of her breasts, prosecutors said.

Another student found out about their tryst and reported it to authorities, sources said.

Morsi’s husband left court without comment, as did Morsi after she made bail.

“This case is particularly disturbing because the defendant is a teacher and schools should be safe havens for children,” Brown said. “Instead, this defendant is accused of sexually preying upon one of her students during rendezvous all over the school.”

After being released on $10,000 bail Tuesday, Morsi was later arrested again over the second affair, cops said. The details were not released.