CHICAGO — A federal judge in Chicago has struck down a key Trump administration rule that allows authorities to deny green cards to immigrants who use food stamps or other public benefits, a blow to the president on the eve of the election.

In a decision issued Monday that applies nationwide, U.S. District Judge Gary Feinerman rejected the rule, which had taken effect recently after the Supreme Court reversed a hold on the policy. Among other things, Feinerman said the rule violates the Administrative Procedure Act, which makes federal agencies accountable to the public by outlining a detailed process for enacting regulations.

The decision marked the latest turn in a complex legal battle over one of President Trump’s most aggressive steps in overhauling the nation’s immigration system. The Chicago lawsuit, filed by Cook County and the Illinois Coalition of Immigrant and Refugee Rights, was among numerous legal challenges to the rule.

Under the policy, immigration officials can deny permanent residency to legal immigrants over their use of food stamps, Medicaid, housing vouchers or other public benefits. Green card applicants had to show they wouldn’t be burdens to the country or “public charges.”

Federal law already requires those seeking permanent residency or legal status to prove they won’t be a “public charge.” But the Trump administration rule included a wider range of programs that could disqualify them.

Immigrant rights advocates deemed it a “wealth test,” while public health experts said it would mean poorer health outcomes and rising costs as low-income migrants chose between needed services and their bid to stay in the country legally. Several cities said such a chilling effect was already evident.

Fred Tsao, senior policy counsel for ICIRR, called the rule an “attack” on legal immigration and criticized the way the Trump administration had instituted policies.

“We may or may not get a new administration,” he said. “If we do, we’d like to see a lot of this damage undone and hopefully some legislative changes that will actually benefit immigrants instead of scaring them away.”

Officials in Cook County, which runs one of the nation’s largest public health systems, argued that when people lack healthcare coverage, they’re less likely to seek preventive care and rely on more expensive emergency care. That also would increase the risk of communicable diseases.

“As we all continue to be impacted by COVID-19, it is vital that no one is fearful of accessing healthcare. The court’s decision to block enforcement of the Public Charge Rule reopens doors for immigrants to access vital services like healthcare,” Cook County Board President Toni Preckwinkle said in a statement.

The Supreme Court voted 5-4 in January to allow the rule to take effect, but enforcement was halted by a federal judge in New York because of the pandemic. But by September, the 2nd U.S. Circuit Court of Appeals had reversed that hold, and the rule went into effect nationwide.

The Trump administration has touted the rule as a way to ensure that only those who are self-sufficient come to the U.S., one of many steps to try to move the country toward a system that focuses on immigrants’ skills instead of emphasizing the reunification of families.

U.S. Citizenship and Immigration Services ceased applying the rule to pending applications and petitions after the ruling in Chicago, agency spokesman Dan Hetlage said in a statement issued Monday evening.

“USCIS will fully comply with the decision and issue additional forthcoming guidance while the agency reviews the decision,” he said.

If there are further appeals, there could be another legal twist in the case.

In June, the 7th U.S. Circuit Court of Appeals upheld Feinerman’s decision blocking enforcement of the rule in Illinois while the merits of the case could be decided. It was a 2-1 decision, with then-Circuit Judge Amy Coney Barrett dissenting.