SAN FRANCISCO (CBS SF) — Santa Clara County and San Francisco won a final victory in a lawsuit Friday challenging President Donald Trump’s threat to withhold federal funding for sanctuary cities and counties.

Trump issued the executive order on Jan. 25, 2017, shortly after being inaugurated. Santa Clara County stood to lose $1.7 billion in federal funding due to its sanctuary county laws, which protect undocumented immigrants from raids by U.S. Immigration and Customs Enforcement, and restrict law enforcement cooperation with federal agencies.

READ MORE: Crews Respond to House Fire in Concord

U.S. President Donald Trump signs two executive orders during a visit to the Department of Homeland Security with Vice President Mike Pence, Homeland Security Secretary John Kelly (R) and other officials January 25, 2017 in Washington, DC. (Chip Somodevilla/Getty Images)

The San Francisco federal court granted Santa Clara County and San Francisco a preliminary injunction in April 2017 protecting both regions from the order, which was later upheld by an appeals court in August 2018.

READ MORE: San Francisco Archbishop, San Diego Bishop Spar Over Biden Receiving Communion

On Friday, the court issued a final ruling creating permanent protections for the sanctuary counties.

“Santa Clara County taxpayers send their tax dollars to Washington and reasonably expect those federal funds will help deliver essential public health and safety services to our County residents and others across the nation, rather than being used as a bargaining chip on federal immigration policy,” Santa Clara County Board President Joe Simitian said in a statement.

MORE NEWS: Early Season Red Flag Warning Sends Residents Scrambling To Protect Homes

© Copyright 2019 CBS Broadcasting Inc. and Bay City News Service. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.