Mayor Bill de Blasio intervened in the prosecution of an accused anti-Semitic attacker — leading to her lock-up in a psych ward — because she was generating negative publicity for his administration, The Post has learned.

Brooklyn’s supervising judge was forced to hold an unscheduled hearing late on the afternoon of New Year’s Eve after City Hall contacted the state Office of Court Administration about Tiffany Harris, 30.

Harris’ repeated release from custody after back-to-back arrests late last month — including for allegedly slapping three Orthodox Jewish women and shouting “F-U, Jews!” on Dec. 27 — had made her a symbol of revolving-door justice amid the state’s new bail reform law and de Blasio’s gift programs for newly released jail inmates.

The administration flipped out when it learned that Harris had allegedly pinched a social worker Dec. 30 after she was let loose under supervised release following her second arrest, said a source familiar with the matter.

“The Mayor’s Office was deeply concerned after learning that she was not in compliance with her supervised release and her erratic behavior was continuing,” the source said. “They reached out to the court, who then calendared it to further investigate.”

A transcript of the court hearing shows her public defender complained to Judge Michael Yavinsky that news coverage had led the Mayor’s Office of Criminal Justice to contact both her and Brooklyn Justice Initiatives, which was responsible for overseeing Harris.

“The mayor of the executive branch of the government got involved because of a press case,” said Lisa Schreibersdorf, founder and executive director of Brooklyn Defender Services.

The state’s bail reform law — which eliminates cash bail for all misdemeanors — was set to take effect New Year’s Day, she noted.

De Blasio has criticized aspects of that law, but has also offered incentives — including gift cards and free Mets tickets — to encourage defendants to show up in court.

“We’re on the cusp of reform taking place in a few hours from now, and that was not the press they wanted, so what they did was they tried to find a way to intervene in the court process in a different branch of government, getting everybody involved in trying to address this,” Schreibersdorf said.

Schreibersdorf — who appeared in court without Harris — decried the notion that her client’s next appearance should be moved up because of outside intervention.

But Yavinksy said he would still issue a bench warrant for Harris’ arrest. She was nabbed by city sheriff’s deputies at a Brownsville hotel around 10:15 p.m New Year’s Eve, then ordered held the next day for a 72-hour psychiatric evaluation at an undisclosed facility.

She has since been admitted for mental health observation “at the discretion of her doctor,” said a source familiar with her care.

De Blasio spokeswoman Freddi Goldstein said Sunday, “It is our job to help ensure supervised release works as it should.

“In that vein, we spoke with the Office of Court Administration after Ms. Harris’ assessment was left incomplete to determine next steps and discuss how to handle situations like this in the future.”