The city Department of Education has failed to fire a teacher rated “unsatisfactory” for six consecutive years. Ann Legra, 44, a first-grade teacher at PS 173 in Washington Heights, racked up “six years of failing her students,” the city ­argued in a 16-day termination hearing.

But Ginsberg dismissed evidence that Legra was a lousy instructor, saying she didn’t get enough coaching.

He imposed only a 45-day suspension without pay. Legra keeps her $84,500-a-year salary, but is now assigned to a pool of 1,400 teachers who serve as substitutes.

Gov. Cuomo last month called the teacher-evaluation system “baloney” after the latest results revealed that fewer than 1 percent of the state’s teachers were rated ineffective.

Legra’s case shows the problem runs much deeper. Even years-long poor performers can escape the ax.

“Six U-ratings is an outrage. It’s a black eye on the system,” said Michael Mazzariello, a former chief prosecutor for the DOE. He faulted administrators and current lawyers.

The DOE said the case is under review. “We are committed to having great teachers at the front of all our classrooms,” said spokeswoman Devora Kaye.

Ginsberg’s ruling came the second time the DOE brought charges against Legra, who was hired as an aide 23 years ago and became a teacher at PS 173 in 2001, officials said.

In a prior settlement, she admitted excessive absences from 2009 to 2012. The DOE let her off with a $2,500 fine.

This time, the DOE took Legra to an administrative trial.

In one example of her poor management, PS 173 Assistant Principal Kevin Goodman found Legra’s classroom in “chaos.”

“Students up out of their seats, at least one was running, another was demonstrating karate moves on the closet door and the majority of the students were not involved in anything instructional — an issue that has repeatedly plagued your tenure as a classroom teacher,” he wrote at the time.

Three of her 6-year-olds were injured in a classroom melee that day, he added.

Amid the “mayhem,” Goodman wrote, Legra was “buried in a corner at a computer table” where she could not monitor all the kids.

Legra said she was “re-sharpening pencils” that were too sharp — to prevent accidents. She claimed the students were “walking around the room working on word activities.”

Over the school year, Legra was absent 27 times and late 37 times. Legra said she suffers asthma and had to go to court for a custody fight with her ex.

Job protections for tenured teachers make it difficult to fire bad apples. The system requires that each charge be proven in a trial with witnesses, documents and arguments. The DOE must show the teacher was given training and chances to improve.

The hearing officers — picked jointly by the DOE and the teachers union — frequently balk at termination, instead ordering a fine or suspension and requiring the teacher to take courses.

Legra, approached by The Post at her home in Fort Lee, NJ, first insisted she was not the PS 173 teacher, but a friend named Margaret Morel — a mix of her middle name and married surname.

Legra later claimed she was ­harassed and targeted because of her high salary.

“They really want to get rid of workers who are there for a long time,” she said. She also complained she had no help with some special-needs kids.

Legra has since filed a federal lawsuit against the DOE, charging discrimination based on her race, gender, national origin and medical disability.