A lawsuit filed in U.S. District Court in Washington on Thursday alleges the Trump administration is illegally jailing asylum seekers with credible cases for months on end in an attempt to deter them and others from seeking refuge in the United States.

The American Civil Liberties Union and other groups filed the class-action lawsuit on behalf of nine detained asylum seekers from Haiti, Venezuela and other countries. They are asking a judge to order the administration to follow a 2009 policy that allows officials to release foreigners while they await their immigration court hearings, a process that can take years.

Among the plaintiffs are Ansly Damus, a 41-year-old ethics teacher who said he was attacked by a gang in Haiti that beat him, set his motorcycle ablaze and threatened to kill him for criticizing a politician. He won his asylum case — twice — but has spent 16 months in detention, most recently in Ohio, while the government appeals.

Other plaintiffs are Alexi Montes, an 18-year-old gay man harassed and beaten in Honduras and who has a relative in Virginia; Abelardo Asensio Callol, a 30-year-old software engineer from Cuba who refused to join the Communist Party or rally for the now-deceased Cuban leader Fidel Castro; and, an unnamed father of two from Mexico who said a drug cartel kidnapped his two brothers and threatened to kill him and his family.

All were initially deemed to have had credible stories and are entitled to a hearing before an immigration judge, lawyers said. While awaiting those hearings, they have been jailed for months.

“The fact that we are doing this to people . . . is really outrageous,” said Michael Tan, a New York-based staff attorney for the ACLU. “What they’re doing here is using detention to send a message that asylum seekers need not apply and they’re not welcome here in the United States.”

The legal challenge comes as the Trump administration engineers a wide-ranging review of the nation’s immigration policies and asylum fraud, which it blames in part for a backlog in the immigration courts of more than 600,000 cases, triple the number in 2009.

Attorney General Jeff Sessions said last year that the asylum system is being “gamed” by foreigners and “dirty immigration lawyers.” Instead of a lifeline to people in peril, he said, it had become an “easy ticket to illegal entry into the United States.”

The Justice Department has also said it wants to slash the immigration court docket of 600,000 cases in half by 2020.

The ACLU lawsuit is filed against the Department of Homeland Security and its sub-agency, Immigration and Customs Enforcement, which detains immigrants, and the Justice Department, which runs the immigration courts where immigrants can seek bond hearings.

ICE spokeswoman Sarah Rodriguez said the agency does not comment on pending litigation. The Justice Department also declined to comment.

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.

The process often starts at an airport or a land border when a person requests asylum and is interviewed by a federal officer who decides whether the claim seems credible and then refers the case to an immigration judge.

Although the federal government under President Barack Obama also detained asylum seekers — including Damus, the Haitian teacher who is a plaintiff in the lawsuit — the ACLU said the number who are released while their cases are pending has plunged under the Trump administration.

The lawsuit said 96 percent of release requests at five U.S. Immigration and Customs Enforcement field offices — Detroit, El Paso, Los Angeles, Newark and Philadelphia — were denied during President Trump’s first eight months in office. The ACLU estimates that more than 1,000 asylum seekers were detained in 2017 in those field offices.

The ACLU says it is not attempting to interfere with the government’s right to detain people who are flight risks or who pose a danger to society. Instead, they said, they want the government to consider each case individually and release people who do not pose a risk while their cases are pending.

Lawyers argue the Trump administration’s approach is endangering lives by forcing people to choose between staying and risking danger or fleeing and enduring severe conditions while jailed in the United States.

Last year, Martín Méndez Pineda, a journalist from Mexico who said he fled to the United States after receiving death threats and having a gun pointed at his head, spent three months in U.S. detention — which he described as “hell” — before he gave up and went home.

Beyond detaining immigrants, Sessions also recently issued a decision that eliminated a requirement that asylum seekers get a full hearing before an immigration judge. He is considering a separate matter that could affect asylum applications from people fleeing criminal gangs.

Based on the 2009 directive, the Obama administration released thousands of asylum seekers who had passed their credible-fear interviews. But in response to a surge of border crossings in his second term, the administration began locking up women and children from Central America who illegally crossed the border, prompting a lawsuit from the ACLU.

A federal judge in that case, which was also filed in the District, issued a preliminary injunction, saying it was likely unlawful to jail the women and children in the civil immigration system to prevent others from crossing.