BOSTON (AP) — Federal prosecutors have agreed to dismiss charges against a Massachusetts judge accused of helping a man who was living in the U.S. illegally evade an immigration enforcement agent, officials said Thursday.

Prosecutors moved to drop the case against Newton District Judge Shelley Joseph after she agreed to refer herself to a state agency that investigates allegations of misconduct by members of the bench.

“I have concluded that the interests of justice are best served by review of this matter before the body that oversees the conduct of Massachusetts state court judges, rather than in a continued federal criminal prosecution,” Rhode Island U.S. Attorney Zachary A. Cunha said in an emailed statement. “The requirement that Judge Joseph refer herself to the Massachusetts Commission on Judicial Conduct and make certain factual admissions will ensure that review takes place.”

Cunha was assigned to oversee the case after Massachusetts U.S. Attorney Rachael Rollins recused herself. In her previous role as district attorney for Suffolk County, Rollins had been part of a lawsuit seeking to block federal authorities from making arrests at courthouses of people suspected of being in the country illegally.

Joseph and a court officer were charged in 2019 with obstruction of justice on allegations that they schemed to let the man sneak out a back door of the courthouse after a hearing on charges that included drug possession.

The prosecution of a sitting judge sparked outrage from many in the legal community, who slammed the case brought during the Trump administration as politically motivated.

Prosecutors moved to dismiss all charges against Joseph and three charges against ex-courtroom deputy Wesley MacGregor. Prosecutors reached a deferred prosecution agreement with MacGregor on the remaining charge of perjury, which means prosecutors will move to dismiss that charge if he complies with certain obligations.

Joseph’s lawyers said the judge “stands by her innocence,” but “has agreed to refer this matter to the Massachusetts Commission on Judicial Conduct and will fully participate in any review the Commission deems appropriate.”

“This was a patently political indictment, blindly ground in prosecutorial ambition,” defense attorney Thomas Hoopes, said in an emailed statement.

Former U.S. Attorney for Massachusetts Andrew Lelling, who originally charged Joseph, told GBH News that he respected Cunha’s decision.

“What the agreed factual statement carefully avoids is requiring Judge Joseph to confirm or deny that she intentionally conspired to help the defendant evade federal authorities,” Lelling wrote in a statement. “A federal grand jury concluded that she did, and that would be a serious, politically-motivated abuse of her position. It would be in the public interest for the Judicial Conduct Commission to get to the bottom of that question and proceed accordingly, whichever way it comes out.”

Authorities said an immigration agent was in the courtroom to detain the man when he appeared in the Newton courthouse in April 2018. The Dominican man had twice been deported and had been barred from entering the U.S. until 2027, prosecutors said.

Authorities say Joseph’s clerk asked the agent to leave the courtroom and told him that the suspect would be released into the courthouse lobby. Instead, prosecutors said that after the hearing, MacGregor led the defendant downstairs to the lockup and let him out a rear door. The man was caught by immigration officials about a month later.

Under the agreement, Joseph admitted to certain facts that will now be considered by the judicial commission.

In a statement of facts that was filed in court, Joseph agreed she knew an immigration official was waiting to take custody of the defendant at the courthouse. The statement says Joseph instructed the court clerk to turn off the recording device while the defense attorney, prosecutor and judge were having a sidebar conversation about the defendant.

During that conversation, the defense attorney asked Joseph to allow his client to go back downstairs, the statement said. When the judge went back on the court record, the defense lawyer asked if he and his client could go downstairs with an interpreter so they could talk, and Joseph agreed, according to the statement.

Shortly after they went downstairs, the court officer opened the door, allowing the man to escape, the statement said.

GBH News’ Tori Bedford contributed reporting.