State and local law enforcement officials are suing US Immigration and Customs Enforcement for carrying out “unlawful and unconstitutional” civil immigration arrests in and around New York City courthouses.

The lawsuit, filed in Manhattan federal court by New York Attorney General Letitia James and Brooklyn District Attorney Eric Gonzalez, claims the agency’s practice is impeding state court operations — and keeping valuable witnesses from appearing in court due to a fear of being arrested.

“This lawsuit challenges the federal government’s recent unlawful and unconstitutional policy authorizing civil immigration arrests in and around New York State courthouses — a policy that disrupts the effective functioning of our courts, deters victims and witnesses from assisting law enforcement and vindicating their rights, hinders criminal prosecution, and undermines public safety,” reads the complaint, filed Wednesday.

The court papers cite a 2018 decision by ICE to formally reverse a longstanding practice of avoiding courthouses, called the “Courthouse Civil Arrest Directive.”

“In issuing the Directive, ICE failed to account for its harm to state judicial proceedings or to justify the marginal benefits of the Directive against such harm — important factors that any rational decision-maker should have considered,” the document reads.

The suit is asking a judge to vacate the policy — and bar ICE from enforcing it going forward.

An ICE spokeswoman said that courthouse arrests were a longtime practice — and often the agency’s only option.

“ICE’s enforcement activities at courthouses are consistent with longstanding law enforcement practices nationwide,” Rachel Yong Yow said in a statement. “And courthouse arrests are often necessitated by the unwillingness of jurisdictions to cooperate with ICE in the transfer of custody of aliens from their prisons and jails.”