Federal prosecutors announced charges Thursday against a Massachusetts judge who assisted an illegal immigrant in escaping from her courtroom, according to court documents, thwarting the deportation officer who had been waiting to pick him up.

Judge Shelley M. Richmond Joseph, a state judge in Newton, Massachusetts, was heard on a court recording saying she wasn’t going to allow U.S. Immigration and Customs Enforcement to grab the man.

She ordered the ICE officer out of her courtroom, then allowed the illegal immigrant to be taken out the back where he was released through another door, prosecutors said.

“This case is about the rule of law,” said U.S. Attorney Andrew E. Lelling, who said Judge Joseph intentionally interfered with the enforcement of a federal law. “We cannot pick and choose the federal laws we follow, or use our personal views to justify violating the law. Everyone in the justice system — not just judges, but law enforcement officers, prosecutors and defense counsel — should be held to a higher standard.”

Judge Joseph has been suspended without pay, the governor’s office said.

She and a courtroom deputy charged with helping her carry out her plans had their initial appearances before a federal judge Thursday afternoon. They pleaded not guilty and were released without bond, the Boston Globe reported.

The charges are the latest twist in an increasingly bitter debate between anti-Trump and immigrant-rights activists on the one hand, and law-and-order advocates and fans of President Trump, over the federal government’s ability and duty to enforce immigration laws.

Newton is one of a number of communities that reacted to Mr. Trump’s election by declaring itself a sanctuary city — though Newton shuns the label and instead calls itself a “welcoming” city. Under the city’s ordinance, police were instructed not to cooperate with ICE except in cases of a major felony warrant against an illegal immigrant.

But Newton’s courthouse policy specifically grants Department of Homeland Security officers permission to be in the building performing their duties and even gives them approval to enter the court’s lockup to take custody of people.

Jessica Vaughan, policy studies director at the Center for Immigration Services, said she couldn’t imagine Judge Joseph would have obstructed another agency’s attempts to arrest a fugitive drug offender.

“It is astonishing to see the extent to which judges, prosecutors and legislators are willing to go to protect even the criminals among the illegal population, whether by whisking them out of courtrooms to avoid deportation, by reducing sentences, and even refusing bail to allow them to go temporarily back to jail instead of into ICE custody,” she said. “They think of themselves as righteous resisters, but they are really a disgrace to their oath to uphold the rule of law and justice for Americans.”

Jose Medina Perez appeared before Judge Joseph in April 2018, a few days after being arrested by Newton police on drug charges. Local prosecutors said he also faced a fugitive warrant from Pennsylvania.

He had been deported twice before, in 2003 and 2007.

ICE became aware he was in local custody and issued a detainer request and warrant of removal, and an officer showed up at the courthouse to take custody of him, should he be released by the local authorities.

As the case dragged on through the day, Judge Joseph had her clerk order the ICE officer out of the courtroom, telling him to wait in the courthouse lobby. Prosecutors said the officer was assured Mr. Perez would be released through the lobby, should he not be held on the state charges.

With the ICE officer out of the room, the judge, in a conversation captured on the court’s on-the-record recording system, seemed to plot how to keep Mr. Perez out of the officer’s hands.

“ICE is gonna get him?” she said, then wondered, “What if we detain him?”

At one point Judge Joseph stopped the recording — which prosecutors said violated the court’s rules — then re-started the proceedings 52 seconds later. She decided Mr. Perez would be released, then was reminded by her clerk of the ICE officer waiting outside.

“That’s fine. I’m not gonna allow them to come in here,” she said.

Mr. Perez was taken back to the court’s lockup, then Wesley MacGregor, the courtroom officer for Judge Joseph that day, used his key card to release Mr. Perez out the back door, avoiding the ICE officer who had been told to wait in the lobby.

ICE says it managed to arrest Mr. Perez later.

His status wasn’t revealed Thursday.

Thursday’s indictment charges Judge Joseph with conspiracy to obstruct justice, aiding and abetting and obstruction of a federal proceeding.

Mr. MacGregor, who is no longer a court officer, faces those charges plus an additional count of perjury. Prosecutors said he lied to the grand jury last year about his activities, saying he was not aware that an ICE officer was waiting, nor did he know there was an active ICE detainer request on Mr. Perez.

Massachusetts Gov. Charlie Baker, who last year called for the judge to be suspended from the bench, on Thursday praised the state courts’ decision to suspend her.

“Governor Baker believes no one should obstruct federal law enforcement officials trying to do their jobs,” said Lizzy Guyton, the governor’s communications director.

The spokeswoman said the Republican governor is pushing for legislation that would explicitly allow state courts and law enforcement to work with ICE to detain deportation targets.

On the other side is Massachusetts Attorney General Maura Healey, a Democrat and frequent Trump opponent, who called the federal charges “a radical and politically motivated attack on our state and the independence of our courts.”

She did not defend the judge but suggested the state could have handled the matter itself.