In this Jan. 31, 2019, file photo, hundreds of people overflow onto the sidewalk in a line snaking around the block outside a U.S. immigration office with numerous courtrooms in San Francisco. Credit: Eric Risberg | AP

NEW YORK — A federal judge in New York on Friday temporarily blocked President Donald Trump from implementing a plan to deny green cards to many immigrants who use Medicaid, food stamps and other government benefits.

U.S. District Judge George Daniels’ ruling came just four days before the Trump administration was set to start enforcing new rules that would disqualify immigrants from getting legal U.S. residency if they were likely to become a burden on public welfare programs.

In his ruling, Daniels said Trump was redefining immigration rules that had stood since the late 1800s with a new framework that had “no logic.”

Allowing the policy to go into effect now, he said, would have a significant impact on “law-abiding residents who have come to this country to seek a better life.”

“Overnight, the rule will expose individuals to economic insecurity, health instability, denial of their path to citizenship and potential deportation,” Daniels wrote. “It is a rule that will punish individuals for their receipt of benefits provided by our government, and discourages them from lawfully receiving available assistance intended to aid them in becoming contributing members of society.”

Almost simultaneously, a federal judge in California also blocked the policy from taking effect, but that order was more geographically limited to states involved in the case: California, Oregon, Maine, Pennsylvania and the District of Columbia.

The U.S. Justice Department, which was defending the administration’s policy in court, didn’t immediately respond to a request for comment on the ruling.

The lawsuit in New York is one of several legal challenges nationwide to one of Trump’s most aggressive steps to cut legal immigration.

Immigration advocates say the rule changes are discriminatory because they would deny legal residency and visas to immigrants who don’t have money.

The Trump administration has said the rules would ensure that immigrants who are granted residency are self-sufficient.

Federal law already requires immigrants seeking to become permanent U.S. residents to prove they will not be a burden on the country — a “public charge,” in legal terms —but the new rules detail a broader range of programs that could disqualify applicants.

The policy is central to Trump’s longtime goal to slash legal immigration and gear it more for people with employment skills instead of toward family members. Those ideas were part of his pitch for an overhaul of immigration laws during his first year but negotiations faltered in Congress.

On average, 544,000 people apply for green cards every year, with about 382,000 falling into categories that would be subject to the new review, according to the government. Guidelines in use since 1999 refer to a “public charge” as someone primarily dependent on cash assistance, income maintenance or government support.

Under the new rules, the Department of Homeland Security has redefined a public charge as someone who is “more likely than not” to receive public benefits for more than 12 months within a 36-month period. If someone uses two benefits, that is counted as two months. And the definition has been broadened to include Medicaid, housing assistance and food assistance under the Supplemental Nutrition Assistance Program, or SNAP.

Factors like the immigrant’s age, employment status and English-language ability would also be looked at to determine whether they could potentially become public burdens at any point in the future.

Critics say the rule changes are discriminatory and would have the effect of barring immigrants with lower incomes in favor of those with wealth. They consider it a betrayal of Emma Lazarus’ words on the Statue of Liberty, “Give me your tired, your poor, Your huddled masses yearning to breathe free.”

The government has said the rule changes would ensure that those gaining legal residency status are self-sufficient.

Immigrants make up a small portion of those getting public benefits because their legal status often makes them ineligible. An Associated Press analysis of census data shows that non-citizen immigrants with low incomes have a lower rate of using Medicaid, food aid, cash assistance and Supplemental Security Income than their native-born counterparts.

For Medicaid, non-citizen immigrants are only 6.5 percent of participants, while more than 87% are native-born. For food assistance, immigrants are 8.8% of recipients, with over 85 percent of participants being native-born.

Earlier this month, Trump issued a presidential proclamation that says immigrants will be barred from entering the country unless they are to be covered by health insurance within 30 days of entering or have enough financial resources to pay for any medical costs. The measure will be effective Nov. 3. The Migration Policy Institute, a nonpartisan think tank, says it could prohibit the entry of about 375,000 a year, mainly family members who account for a majority of people getting green cards from abroad.