NEW YORK (Reuters) - President Donald Trump’s administration can withhold millions of dollars in law enforcement funds from states and cities that refuse to cooperate with federal immigration authorities, a U.S. appeals court ruled on Wednesday.

FILE PHOTO: U.S. President Donald Trump hosts a "California Sanctuary State Roundtable" at the White House in Washington. U.S., May 16, 2018. REUTERS/Kevin Lamarque

The unanimous decision by a three-judge panel of the 2nd U.S. Circuit Court of Appeals in Manhattan was a victory for Trump in his years-long fight with so-called sanctuary jurisdictions.

It overturned a lower court ruling directing the release of federal funds to New York City and the states of New York, Connecticut, Massachusetts, New Jersey, Rhode Island, Virginia and Washington.

The states and city sued over a 2017 policy conditioning receipt of the funds by state and local governments on their giving federal immigration officials access to their jails, and advance notice when immigrants in the country illegally are being released from custody.

Three federal appeals courts in Chicago, Philadelphia and San Francisco have upheld injunctions barring enforcement of at least some of the administration’s conditions on the so-called Edward Byrne Memorial Justice Assistance Grants.

Wednesday’s decision sets up a possible appeal to the U.S. Supreme Court, which often resolves legal disputes that divide lower courts.

In the decision, Judge Reena Raggi said the case “implicates several of the most divisive issues confronting our country” including immigration policy and law enforcement, illegal immigrants, and the ability of state and local governments to adopt policies the federal government dislikes.

A U.S. Justice Department spokesman called the decision a “major victory for Americans” in recognizing Attorney General William Barr’s authority to ensure that grant recipients do not thwart federal law enforcement priorities.

Trump, a Republican seeking re-election on Nov. 3, takes a hardline stance toward legal and illegal immigration.

His battle against Democratic-led “sanctuary” jurisdictions focuses on laws and policies making it harder for U.S. Immigration and Customs Enforcement officials to find and arrest immigrants they consider deportable.

The funding conditions announced by then-Attorney General Jeff Sessions affected nearly $26 million of annual grants to the seven states and $4 million to New York City.

“It is part of the administration’s campaign to coerce and bully state and local governments to adopt policies it prefers,” said Cody Wofsy, a lawyer at the ACLU Immigrants’ Rights Project, which filed a brief opposing the administration’s conditions.

Wofsy called Wednesday’s decision “a major outlier,” though state and municipalities could still “opt out” of contributing to federal immigration enforcement.

The office of New York Attorney General Letitia James said it was reviewing the decision. New York City’s law department had no immediate comment.

U.S. District Judge Edgardo Ramos in Manhattan in Nov. 2018 declared the conditions unconstitutional, saying the administration acted arbitrarily and capriciously in withholding grants without considering the impact on local law enforcement.

Raggi, however, said the conditions “help the federal government enforce national immigration laws and policies supported by successive Democratic and Republican administrations.”

Byrne was a New York City police officer shot to death at age 22 in 1988 while guarding the home of a Guyanese immigrant helping authorities investigate drug trafficking.

The case is New York et al v U.S. Department of Justice et al, 2nd U.S. Circuit Court of Appeals, Nos. 19-267, 19-275.