A federal judge this week ordered the Trump administration to end visa processing delays for hundreds of Afghan and Iraqi nationals who worked for U.S. forces, giving the government 30 days to propose a plan to end backlogs that have kept many waiting more than four years to enter the United States while facing persecution and death threats.

The ruling Wednesday by U.S. District Judge Tanya S. Chutkan of Washington, D.C., granted class-action status to all applicants whose visa requests have been pending for more than nine months — a deadline set by statute — and followed a September opinion in which the judge called the government’s justification for delays “tortured and untenable.”

“Administrative challenges pale in comparison to the inefficiency, cost, and waste of resources that would result if each applicant (there are hundreds), were to bring individual claims,” Chutkan wrote. The burden of duplicative lawsuits would fall on the courts, the government and plaintiffs and their families, the judge wrote, whose lives “are at risk every day their applications are pending.”

The ruling could mark a watershed for thousands of people who worked for American troops and diplomats and coalition forces as interpreters and other roles since the 2001 and 2003 U.S. invasions of Afghanistan and Iraq. Congress recognized their sacrifice, creating a Special Immigrant Visa program allowing those who face persecution to seek resettlement in the United States.

However, the lawsuit, brought by five anonymous Afghan or Iraqi citizens represented by the International Refugee Assistance Project, revealed that virtually all applicants for Special Immigrant Visas face what the judge called “life-threatening delays,” with former American ambassador Ryan Crocker stating to the court that “the longer an application is delayed, the higher the risk to the applicants and their families.”

Government data showed at least 7,700 applications have been pending for longer than the nine-month benchmark, of which 5,300 have waited an average of 2½ to five years. About 2,300 have waited for a final ruling for an average of three years after getting a background check and approval from the U.S. Embassy, the court found.

“This ruling could finally bring relief to these men and women and their families who have been waiting in fear for far too long,” said a statement from Deepa Alagesan, an attorney for the International Refugee Assistance Project.

Attorney Rebecca Curwin, with the Freshfields Bruckhaus Deringer law firm, which joined the refu­gee assistance project as class counsel, said the group looks forward to “the government’s efficient adjudication of applications that have been pending for years.”

“This decision is an essential step toward keeping our promises to the thousands of Afghans and Iraqis who risked their lives for the United States,” Curwin said.

Attorneys for the government opposed granting class-action certification, saying that some high-risk applicants pose greater “national security concerns” and that Congress permitted it to take “whatever time it needed” to evaluate them.

But Chutkan said the law already provides exceptions for such cases and that such applicants also face unnecessary delays.

“All class members, including those whose applications require additional processing time because they are high-risk, seek and will benefit from the same remedy,” she ruled.