Federal prosecutors charged a state judge and a former court officer in Massachusetts with obstruction of justice on Thursday for allegedly helping an undocumented immigrant escape from an Immigration and Customs Enforcement officer at a courthouse last year.

The indictment of the judge, Shelley M. Richmond Joseph, 51, and the officer, Wesley MacGregor, 56, was a dramatic turn in the long-running clash between the Trump administration and state governments that have resisted its hard-line approach to immigration.

Prosecutors accused Judge Joseph and Mr. MacGregor of letting their beliefs trump federal immigration law when they allegedly helped the man, who was not named in the indictment, sneak out of Newton District Courthouse in Newton, Mass., in March 2018. The judge ordered the man to go to a basement facility, where he was let out a back door, rather than into the lobby, where she knew that an ICE officer was waiting for him, prosecutors say.

“The allegations in today’s indictment involve obstruction by a sitting judge, that is intentional interference with the enforcement of federal law, and that is a crime,” United States Attorney Andrew E. Lelling said in a statement. “We cannot pick and choose the federal laws we follow, or use our personal views to justify violating the law.”