President Donald Trump's executive order threatening to withhold funding from "sanctuary cities" that limit cooperation with immigration authorities is unconstitutional, but a judge went too far when he blocked its enforcement nationwide, a U.S. appeals court ruled Wednesday.

In a 2-1 ruling, the 9th U.S. Circuit Court of Appeals agreed that the order exceeded the president's authority.

"Absent congressional authorization, the administration may not redistribute or withhold properly appropriated funds in order to effectuate its own policy goals," Chief Judge Sidney Thomas wrote for the majority.

But he also said there wasn't enough evidence to support a nationwide ban on the order and sent the case back to the lower court for more hearings on that question.

An email to a spokesman for the U.S. Justice Department was not immediately returned.

U.S. District Judge William Orrick said in November that the order threatened all federal funding and that the president did not have the authority to attach new conditions to spending that was approved by Congress.

The ruling came in lawsuits filed by two California counties — San Francisco and Santa Clara. The executive order potentially jeopardized hundreds of millions of dollars in funding to the two counties, Orrick said, citing comments by Trump and U.S. Attorney General Jeff Sessions as evidence of the order's scope.

The Trump administration said the order applied to a relatively small pot of money that already required compliance with immigration law.

Government attorney Chad Readler had told Orrick that the order applied to only three Justice Department and Homeland Security grants that would affect less than $1 million for Santa Clara and possibly no money for San Francisco.

During arguments before the 9th Circuit in April, Thomas asked what the court was supposed to make of statements by Trump and his administration about wanting to withhold money from sanctuary cities.

Thomas also questioned whether the order would be constitutional if it applied to all types of funding, as the lower-court judge found.

Readler said the order was much narrower, and the judges should not focus on comments by the president or other administration officials.

The executive order is part of a push by the Trump administration to crack down on cities and states that generally don't comply with U.S. immigration authorities.

The administration has sued California over three laws aimed at protecting immigrants in the country illegally. It also has moved to block a key public safety grant from going to sanctuary cities and states.

The Trump administration says sanctuary jurisdictions allow dangerous criminals back on the street. San Francisco and other sanctuary cities say turning local police into immigration officers erodes the trust needed to get people to report crime.