MANHATTAN (CN) – Reversing a sweeping injunction, the Second Circuit gave the Justice Department a green light Wednesday to withhold funding from New York City and seven states in retaliation for their sanctuary policies on immigration.

“The case implicates several of the most divisive issues confronting our country and, consequently, filling daily news headlines: national immigration policy, the enforcement of immigration laws, the status of illegal aliens in this country, and the ability of states and localities to adopt policies on such matters contrary to, or at odds with, those of the federal government,” wrote U.S. Circuit Judge Reena Raggi, a George W. Bush appointee, on behalf of a unanimous three-judge panel.

Then-Attorney General Jeff Sessions announced the Justice Department’s clampdown on sanctuary jurisdictions nearly three years ago, saying cities and states that refuse to help federal agents detain undocumented immigrants at local jails would lose out on $385 million in justice assistance grants.

JAG grants, as they are known, are named for slain New York City police officer Eddie Byrne.

Seven states — New York, Connecticut, New Jersey, Washington, Massachusetts, Virginia, and Rhode Island — and New York City sued over the restrictions, winning a ruling some 15 months ago in Manhattan that forced the Justice Department to release the funding.

“This case is fundamentally about the separation of powers among the branches of our government and the interplay of dual sovereign authorities in our federalist system,” U.S. District Judge Edgardo Ramos wrote on Nov. 30, 2018.

The Second Circuit found that Ramos’s ruling “thoughtful” but ultimately wrong.

“These conditions help the federal government enforce national immigration laws and policies supported by successive Democratic and Republican administrations,” the 77-page opinion states. “But more to the authorization point, they ensure that applicants satisfy particular statutory grant requirements imposed by Congress and subject to Attorney General oversight.”

U.S. Circuit Judges Ralph Winter, a Reagan appointee, and Jose Cabranes, a Clinton appointee, joined the decision.

New York City Mayor Bill de Blasio said the challengers will prevail.

“We’ll see President Trump back in court and we will win,” de Blasio said in a statement.

“President Trump’s latest retaliation against his hometown takes away security funding from the No. 1 terrorist target in America — all because we refuse to play by his arbitrary rules,” de Blasio continued . “No one knows how to keep New Yorkers safe better than the men and women of the NYPD. The president is starving them of the very resources named in honor of one of New York’s Finest, Officer Eddie Byrne.”

Should the city appeal the Second Circuit’s decision en banc before its full 13-member court, the sanctuary jurisdictions will be facing a panel that Trump succeeded in stacking with Republican appointees.

The Justice Department did not immediately respond to requests for comment.