A Manhattan federal court judge has issued a nationwide order blocking the Trump administration from enforcing a new regulation that would make it easier to deny green cards and visas to immigrants who might need public assistance in the future.

Judge George Daniels’ Friday ruling came just days before the so-called “public charge” rule was set to go into effect on Oct. 18.

The new rule would have made it possible to brand any immigrant with the potential to end up on public assistance as a burden, and consider that in deciding to issue green cards or visas.

The scathing ruling excoriated President Donald Trump’s lawyers for “stumbling along” during oral arguments when asked to explain the rationale behind making changes to the longstanding law, which has operated under the same definition since the 1880s.

“The Rule is simply a new agency policy of exclusion in search of a justification,” Daniels wrote. “It is repugnant to the American dream of the opportunity for prosperity and success through hard work and upwards mobility.”

New York Attorney General Letitia James lauded the ruling. James and other attorneys general sued in August to block the rule change from taking effect.

“The history of our nation is inextricably tied to our immigrant communities, and because of today’s decision, so too will be our future,” James said in a statement.

“Once again, the courts have thwarted the Trump Administration’s attempts to enact rules that violate both our laws and our values, sending a loud and clear message that they cannot rewrite our story to meet their agenda.”

Lawyers for Trump did not immediately return a request for comment.