By Tom Hals

June 20 (Reuters) - A federal judge on Thursday ruled that U.S. immigration authorities cannot arrest illegal immigrants at Massachusetts courthouses, the first order of its kind barring courthouse arrests.

U.S. District Judge Indira Talwani in Boston issued an injunction preventing Immigration and Customs Enforcement, or ICE, from carrying out a directive authorizing arrests of illegal immigrants in the state's courts.

Talwani enjoined the directive until the case proceeds to a trial, noting in the opinion that as long as the threat of arrests hangs over the state's courts "some state criminal and civil cases may well go unprosecuted for lack of victim or witness participation."

The judge's order did not apply to criminal arrests by ICE, although most of the agency's arrests are civil arrests for violating immigration laws.

ICE did not immediately respond to a request for comment.

"This is definitely the first injunction of its kind," said Oren Nimni, of Lawyers for Civil Rights, one of the attorneys who brought the case.

President Donald Trump has been focused on removing immigrants in the country illegally, and said on Tuesday officials would soon begin large-scale arrests.

Local governments dubbed "sanctuary cities" have resisted cooperating with the Trump administration's efforts to round up illegal immigrants.

The January 2018 ICE directive to patrol courthouses was adopted partly in response to local governments refusing to transfer illegal immigrants to ICE upon their release from custody. Courthouses were one of the few reliable places to find people.

The plaintiffs in the case - prosecutors, a group that represents indigent defendants and a rights group - said people who feared being arrested by ICE agents were also unable to go to court to seek protection from a violent partner or make a complaint for unpaid wages.

In April, U.S. prosecutors charged a Massachusetts judge and a court officer with conspiracy and obstruction, saying they blocked an ICE officer from arresting an illegal immigrant at a 2018 court proceeding. (Reporting by Tom Hals in Wilmington, Delaware; editing by Jonathan Oatis)