A law enforcement officer walks past ICE emblem at the U.S. Immigration and Customs Enforcement headquarters in 2017. (Salwan Georges/The Washington Post)

A federal judge in Washington on Monday ordered the U.S. government to immediately release or grant hearings to more than 1,000 asylum seekers who have been jailed for months or years without individualized case reviews, dealing a blow to the Trump administration’s crackdown on migrants.

U.S. District Judge James E. Boasberg of Washington said U.S. Immigration and Customs Enforcement ignored its own policy stating that asylum applicants who establish a “credible fear” of persecution in their native country must be granted a court hearing within seven days or released.

He granted a preliminary injunction preventing the government from carrying out blanket detentions of asylum seekers at five large U.S. field offices, including those currently held, pending resolution of the lawsuit.

The American Civil Liberties Union and other groups sued in March after finding detention rates at the offices surged to 96 percent in the first eight months after President Trump took office in 2017, up from less than 10 percent in 2013.

The ACLU says the mass imprisonment of people seeking refuge while awaiting immigration court hearings stems from policies promoted by Trump and Attorney General Jeff Sessions that amount to a deterrent to using the asylum provision. The policy, the ACLU argued, unlawfully denies asylum seekers as a group based on only one of the factors used to assess the danger an individual poses: how long they have been in the United States.

“As the events of recent months make clear, the question of how this nation will treat those who come to our shores seeking refuge generates enormous debate,” Boasberg wrote in a 38-page opinion, an allusion to the administration’s family-separation policy recently implemented and then abandoned amid international condemnation.

“This Opinion does no more than hold the Government accountable to its own policy, which recently has been honored more in the breach than the observance. Having extended the safeguards of the Parole Directive to asylum seekers, ICE must now ensure that such protections are realized,” Boasberg said.

The lawsuit was filed on behalf of nine detained asylum seekers from Haiti, Venezuela and other countries who were initially determined to have credible stories and have been jailed for up to two years awaiting a hearing before an immigration judge, lawyers said. Two have been granted asylum and released since the case was filed in March, said attorneys with the ACLU and the Covington & Burling law firm.

The court action named the Department of Homeland Security and its sub-agency ICE, which detains immigrants, and the Justice Department, which runs the immigration courts where immigrants can seek bond hearings.

The five ICE field offices cited in the lawsuit are Detroit, El Paso, Los Angeles, Newark and Philadelphia, which handle about one-fourth of the nationwide caseload. Plaintiffs said the government at an earlier stage identified nearly 800 class members, a figure they said has now exceeded 1,000.

“This ruling means the Trump administration cannot use indefinite detention as a weapon to punish and deter asylum seekers,” said Michael Tan, senior staff attorney with the ACLU’s Immigrants’ Rights Project.

Hardy Vieux, legal director for Human Rights First, which also backed the lawsuit, said the decision will have “an enormous impact” on asylum seekers who pose no risk, adding, “It is a rejection of the Trump administration’s blanket policy of denying parole to those seeking protection in this country.”

A Justice Department spokeswoman did not respond to a request for comment or to a question about whether the government will appeal.

Boasberg cited a 2009 Department of Homeland Security directive still in force that says the federal government must consider person by person whether an undocumented asylum seeker poses a flight risk or danger to the community, or can be released from detention once they have shown a “credible fear” of persecution in their home country.

Boasberg granted provisional class status to asylum seekers. While the lawsuit is ongoing, the judge barred ICE from detaining applicants for more than seven days without doing a personalized review of their asylum claim, and giving specific written explanations for anyone the government says must be held.

The Justice Department said the case should be thrown out arguing that asylum detention decisions are the sole discretion of government agencies and insulated from court review to prevent asylum applicants from flooding courts with lawsuits.

ACLU Deputy Legal Director Cecelia Wang said the lawsuit targeted another area where the Trump administration has been using “inhumane and illegal” policies of detaining border-crossers to deter others.

Asylum is a provision in federal law that allows foreign nationals to seek permanent residency and eventually, citizenship, if they have a fear of persecution based on their race, religion, nationality, political opinion or “membership in a particular social group,” a broad category that has included people fleeing gang activity, domestic violence or other circumstances including torture or death.

Boasberg in 2015 blocked a major Obama administration initiative of detaining most women and children caught crossing the border illegally whether they had applied for asylum in the United States, saying invocations of national security or deterrence must give way to individualized determinations.