A Massachusetts judge conspired with a court officer to help a twice-deported undocumented immigrant slip out a back exit of a courthouse and elude arrest by immigration authorities, according to an indictment unsealed Thursday.

Judge Shelley Joseph and court officer Wesley MacGregor were hit with federal obstruction of justice charges for allegedly aiding the defendant, who was arrested in March 2018 on charges of drug possession and being a fugitive from justice, according to an indictment by the U.S. Attorney's Office in Boston.

The man, identified as A.S., was allowed to dash out of a rear sally port entrance at the state courthouse in Newton, Massachusetts, on April 2, 2018, after a plainclothes immigration enforcement agent identified himself to the judge and other courtroom personnel, federal prosecutors said.

“This case is about the rule of law,” said United States Attorney Andrew E. Lelling.

"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."

Download the NBC News app for breaking news and politics

The plan was hatched after the suspect's lawyer told the judge he thought the U.S. Immigration and Customs Enforcement officer in the courthouse was targeting the wrong person.

"ICE is going to pick him up if he walks out the front door. But I think the best thing for us to do is clear the fugitive issue, release him on a personal, and hope that he can avoid ICE," the attorney said during a sidebar that was recorded, according to the indictment. "…That’s the best I can do."

The judge responded: "ICE is gonna get him? What if we detain him?" according to the indictment.

Joseph then requested that the courtroom recorder be turned off as the conversation continued, prosecutors say. The courtroom recorder was turned back on after 52 seconds, the indictment says.

At that point, the prosecutor agreed with the defense lawyer that it seemed to be a case of mistaken identity.

"With the information that I have, I don't think that there is enough tying him to the Pennsylvania warrant," the prosecutor said, according to the indictment.

It was not clear what happened to the undocumented immigrant after the courthouse escape.

The ACLU of Massachusetts released a statement slamming the decision to prosecute the judge and court officer.

"The Department of Justice's decision to bring this case is preposterous, ironic, and deeply damaging to the rule of law," said executive director Carol Rose.

"This decision seems to have little to do with the actual facts, and everything to do with enforcing the president’s anti-immigrant agenda. This prosecution is nothing less than an assault on justice in Massachusetts courts, and it will further undermine community trust and safety."

Joseph, 51, and MacGregor, 56, were indicted on one count of conspiracy to obstruct justice and two counts of obstruction of justice — aiding and abetting, authorities said. MacGregor was hit with an additional perjury count for falsely telling a grand jury that he was unaware an ICE agent was in the courtroom seeking to detain the defendant, authorities said.

They both pleaded not guilty and were released without bond. Lawyers for the pair could not be reached.

Joseph, who was appointed as a Massachusetts District Court Judge in November 2017, was suspended without pay, according to a judicial order obtained by NBC Boston.

“The actions of the judge in this incident are a detriment to the rule of law and highly offensive to the law enforcement officers of ICE who swear an oath to uphold our nation’s immigration laws,” said Todd M. Lyons, acting field director of enforcement and removal operations for ICE in Boston.

This is a developing Story. Check back for updates.