A judge has barred federal authorities from arresting people at Massachusetts courthouses for civil immigration violations while a lawsuit challenging the practice plays out.

U.S. District Judge Indira Talwani issued the decision Thursday in the lawsuit brought against U.S. Immigration and Customs Enforcement (ICE) in April by public defenders and two Massachusetts district attorneys.

In her decision, Talwani ordered ICE to stop, "civilly arresting parties, witnesses, and others attending Massachusetts courthouses on official business while they are going to, attending, or leaving the courthouse."

The lawsuit alleges the practice by ICE is scaring victims and defendants away from court and making it harder for prosecutors to hold people accountable.

The judge's preliminary injunction is believed to be the first judicial decision of its kind in the country. The case was brought by Middlesex District Attorney Marian Ryan and Suffolk District Attorney Rachael Rollins, both Democrats.

"This is a huge victory," said Oren Nimni, an attorney with Lawyers for Civil Rights. "ICE has been running rampant across courthouses, stalking immigrants as they go in to get restraining orders against abusive partners or deal with other civil or criminal matters, and it's been taking a huge toll on immigrant communities."

Gladys Vega, the executive director of the Chelsea Collaborative, an immigrant rights group that is named as one of the plaintiffs, said she had tears in her eyes when she heard about the injunction.

"We were feeling hopeless because victims of domestic violence, there were victims of fraud, were not attending court hearings," she said, "or were not putting claims at the court because they were so afraid of the presence of ICE in the courtrooms."

The ruling doesn't affect the agency's ability to arrest people on civil violations when they're already in custody or detain people on criminal matters.

John Mohan, a spokesman for ICE, said the agency "respects the ruling of the court" and is reviewing the decision. He said the agency will issue a written statement later Thursday.

Talwani's order comes at a time when in the same courthouse, Massachusetts U.S. Attorney Andrew Lelling is prosecuting a state trial court judge for allegedly helping an undocumented immigrant evade ICE arrest in her courtroom.

With additional reporting from The Associated Press. This report comes from the New England News Collaborative: eight public media companies, including The Public's Radio, coming together to tell the story of a changing region, with support from the Corporation for Public Broadcasting.