A Bronx high school teacher was discovered hiding in the bedroom of one of her female students, disturbing disciplinary records show.

Tamara A. Alvarez, 35, who taught history at the Bronx HS for Writing and Communication Arts, was spotted in the girl’s room “hiding behind the bed,” leading officials to allege an improper romantic relationship between the two.

The city Department of Education contended Alvarez had an “obsession” with the girl. The teacher claimed the DOE targeted her because she is a lesbian. A hearing officer gave Alvarez the ax.

Questions arose when the student’s mom was in the hospital with a broken foot in May 2017, and asked her boyfriend to check on the teen, according to a report on Alvarez’s disciplinary hearing.

When the boyfriend entered the apartment about 11 p.m., no one was home, he testified. He soon heard someone come inside and go into the girl’s bedroom.

He knocked on the bedroom door, but no one answered. After the daughter got home, they opened the door and saw “a woman hiding behind the bed.”

The mother’s boyfriend then told the woman to leave, he testified, but the upset daughter also left and did not return to live with the family, the report says.

The shocking incident followed an argument when the girl told her mom and mom’s boyfriend that “she was dating a woman in her late 20s,” but refused to introduce them to the woman.

The mom’s boyfriend later identified the woman in the bedroom as Alvarez after seeing her on stage at the school’s graduation ceremony. The student was angry at her mom for reporting Alvarez, saying “Mom, why are you doing this? She has kids.”

The city’s Special Commissioner of Investigation then searched phone records, finding that Alvarez had called or texted the girl about 800 times between February and May 2017; the girl had contacted the teacher about 500 times.

The contacts occurred multiple times a day and late at night. Many were lengthy — up to four hours at a time.

“Her involvement with this student is simply an obsession,” a Department of Education lawyer argued.

Alvarez insisted she was only trying to help the girl, who was struggling in school, and that the DOE had no rules limiting the length of phone conversations between teachers and students.

“We’re here because [Alvarez] is a lesbian,” her lawyer contended. “This is the very definition of unequal treatment.”

Alvarez denied going into the girl’s bedroom, but didn’t show up when the mom’s boyfriend testified at the hearing.

Hearing officer Sarah Miller Espinosa did not buy the teacher’s defense. In a Jan. 3 termination decision, Espinosa said Alvarez “targeted a vulnerable special education student” and “violated her position of trust.”