A U.S. appeals court said Wednesday that the Trump administration cannot deny funding to so-called "sanctuary cities" that refuse to cooperate with federal immigration authorities is unconstitutional.

The 9th U.S. Circuit Court of Appeals ruled 2-1 that President Trump went beyond his authority with an executive order he signed, saying the executive branch may not refuse to disperse the federal grants without the approval of Congress.

“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 in the majority opinion.

However, the appeals also determined that a lower court may have gone too far when it issued a nationwide injunction against Trump's executive order because the defense did not provide adequate evidence showing how it could cause harm in cities outside of California. The case is being sent back to the lower court to address that matter.

In response to two lawsuits filed by San Francisco and Santa Clara counties, a federal judge ruled in November that the president cannot set new conditions on spending approved by Congress after the administration argued the order applied only to a small portion of funds. The Trump administration then appealed the decision to the 9th Circuit.

The executive order was part of Trump administration efforts to crack down on sanctuary cities and jurisdictions that offer protections to people in the U.S. illegally.

Attorney General Jeff Sessions announced in July 2017 that cities and states would only be eligible for certain grants from the Department of Justice if they complied with federal immigration law.

[Also read: GOP bill would make first-time illegal border crossing a felony, send sanctuary city funds to ICE]