LOS ANGELES — Here in Los Angeles, where nearly half of the city’s residents are Latino, Mayor Eric Garcetti has vowed to do everything he can to fight widespread deportations of illegal immigrants.

In New York, with a large and diverse Latino population, Mayor Bill de Blasio has pledged not to cooperate with immigration agents. And Mayor Rahm Emanuel of Chicago has declared that it “will always be a sanctuary city.”

Across the nation, officials in sanctuary cities are gearing up to oppose President-elect Donald J. Trump if he follows through on a campaign promise to deport millions of illegal immigrants. They are promising to maintain their policies of limiting local law enforcement cooperation with federal immigration agents.

In doing so, municipal officials risk losing millions of dollars in federal assistance for their cities that helps pay for services like fighting crime and running homeless shelters. Mr. Trump has vowed to block all federal funding for cities where local law enforcement agencies do not cooperate with Immigration and Customs Enforcement agents.