SAN FRANCISCO—The city of San Francisco has sued to block an executive order issued by President Donald Trump last week that would withhold more than $1 billion in federal funding from the city due to its “sanctuary city” policies.

President Trump signed an executive order on Jan. 25 directing federal officials to identify funds that could be withheld from sanctuary cities, a term describing about 300 communities that refuse to cooperate with federal immigration officials in aiding deportation.