A federal judge in California blocked President Trump’s planned phaseout of the Obama-era DACA deportation amnesty in a ruling late Tuesday that could upend the negotiations on Capitol Hill over “Dreamers” future.

Judge William Alsup, a Clinton appointee to the bench, ruled the DACA program legal — the first court to do so — and said the administration illegally cut corners in canceling it.

He ordered the administration to allow illegal immigrants to renew their DACA applications just as they would have under President Obama.

SEE ALSO: White House slams judge’s halt to DACA phaseout: ‘Outrageous’

“The agency shall post reasonable public notice that it will resume receiving DACA renewal applications and prescribe a process consistent with this order,” the judge said.

The ruling is a major victory for immigrant-rights groups who had challenged Mr. Trump’s phaseout.

One of those challengers was former Homeland Security Secretary Janet Napolitano, who created the DACA program in 2012, without going through the full notice-and-comment period. Ms. Napolitano said that while her action was legal, canceling DACA without notice-and-comment was not legal.

Judge Alsup agreed with Ms. Napolitano, who sued in her new role as president of the University of California system, along with the state of California and several other challengers.

The judge, in his ruling, said the 2012 DACA program, while not approved by any law, appeared to be supported by years of practice in administrations of both parties.

“In extending programmatic deferred action to DACA enrollees, the agency acted within the scope of this long and recognized practice,” the judge said.

The ruling contradicts other federal judges, including the 5th U.S. Circuit Court of Appeals, which rules a program similar to DACA was illegal because it not only didn’t go through notice-and-comment, but it also was contrary to immigration law.

Judge Alsup said the DACA case was different enough that he didn’t feel bound by that logic, and he blasted the Trump administration for caving to legal threats from Texas and other states opposed to DACA based on that circuit’s ruling.

Mr. Trump and his aides had concluded the program was illegal and ordered a six-month phaseout, concluding March 5.

Josh Blackman, a professor at South Texas College of Law, called Tuesday’s ruling “surreal.”

In a series of Tweets, he said the 5th Circuit’s ruling on the broader 2014 Obama immigration amnesty was based heavily on the operations of DACA.

“The upshot is that because the Trump Administration understood executive power in a more narrow fashion than did the Obama administration, the former acted arbitrarily and capricious. I’ve never seen anything quite like it,” he said.

Mr. Trump’s decision to phase out DACA set off a scramble on Capitol Hill, where Democrats and Republicans began to search for a more permanent solution for nearly 700,000 people still protected by the DACA program.

Those conversations came to a head Tuesday when Mr. Trump convened a meeting at the White House with Democrats and Republicans. Both sides agreed to try to reach an agreement, with Democrats insisting a speedy resolution was needed to beat Mr. Trump’s phaseout.

If Judge Alsup’s ruling stands, it could eliminate the need for speed, upending those negotiations.

Judge Alsup did allow some exceptions to his ruling reinstating DACA. While current and past recipients could apply for renewal, he said no people who hadn’t applied for DACA before could join now.

DACA recipients can also still be deported if the government has good reason, the judge said.

And he said the government doesn’t have to continue issuing “advance parole” to DACA recipients. Many of those recipients had used the advance parole system as a backdoor pathway to citizenship under Mr. Obama.