(CNN) San Francisco on Tuesday became the first city in the US to file a lawsuit over President Donald Trump's executive order targeting sanctuary cities.

Signed January 25, the order aims to crack down on sanctuary cities, the term for jurisdictions with policies that limit cooperation between or involvement with federal immigration enforcement.

The order threatens to withhold federal funding from cities that hinder efforts to capture and deport undocumented immigrants. It contends they harm public safety.

Cities with diverse immigrant populations have adopted various forms of sanctuary laws to counter what some considered extreme federal immigration policies, especially for minor, nonviolent crimes.

San Francisco's lawsuit alleges the executive order is unconstitutional and exceeds the President's power. It claims the city already complies with applicable federal law and seeks to prevent the government from cutting off funding.

"The president's executive order is not only unconstitutional, it's un-American," City Attorney Dennis Herrera said at a news conference. "This country was founded on the principle that the federal government cannot force state and local governments to do its job for it, like carrying out immigration policy. I am defending that bedrock American principle today."

An ideological clash

Mayors of several sanctuary cities, including San Francisco, New York and Los Angeles, have vowed to fight the order, saying it will unravel delicate relationships between immigrant communities and law enforcement and tear apart families.

Sanctuary city supporters believe that undocumented immigrants should be shielded from possible deportation when they report crimes.

One exception is Florida's Miami-Dade County, where the Republican mayor has ordered jails there to "fully cooperate" with President Donald Trump's crackdown on sanctuary cities.

The lawsuit cites an analysis by a University of California, San Diego associate professor finding crime is statistically significantly lower in sanctuary counties compared to nonsanctuary counties. The study found that economies are stronger, based on various data points, from higher median household income, less poverty and less reliance on public assistance to higher labor force participation, higher employment-to-population ratios and lower unemployment.

"San Francisco is safer when all people, including undocumented immigrants, feel safe reporting crimes," the lawsuit claims. "San Francisco is healthier when all residents, including undocumented immigrants, access public health programs. And San Francisco is economically and socially stronger when all children, including undocumented immigrants, attend school."

It's no secret that President Trump views sanctuary cities as crime-ridden havens for illegal immigration.

Ending sanctuary cities was one of his top campaign promises, with San Francisco a frequent case in point. The shooting death of San Francisco resident Kate Steinle, allegedly by an undocumented immigrant, in particular became a rallying cry for Trump on the campaign trail.

As the executive order declares, "Sanctuary jurisdictions across the United States willfully violate Federal law in an attempt to shield aliens from removal from the United States. These jurisdictions have caused immeasurable harm to the American people and to the very fabric of our Republic."

What's in San Francisco's sanctuary city law?

San Francisco has been a sanctuary city since 1989, when the city began to enact ordinances in response to the influx of Central American refugees fleeing civil wars, according to the lawsuit.

Its law does not prevent undocumented immigrants from being prosecuted for criminal activity.

In general, the law prohibit city employees from using city funds or resources to assist in the enforcement of federal immigration law, unless required by federal or state law. They specifically prohibit local law enforcement officers from cooperating with Immigration and Customs Enforcement requests to hold people eligible for release on immigration offenses, and limit when local law enforcement officers may give ICE advance notice of a person's release from local jail.

What's at stake?

The order deprives San Francisco of its sovereign power to choose how it devotes resources and forces it "to carry out the agenda of the Federal government," the lawsuit alleges.

San Francisco receives more than $1.2 billion a year in federal funding, most of which goes to health care, nutrition and other safety net programs, the city said in a statement.

"The Executive Order threatens the loss of more than $1 billion in federal funds that support vital services, the loss of community trust, and the loss of San Francisco's sovereign authority to set and follow its own laws on matters appropriately and historically within the control of local government."