Several prominent mayors pulled out of a meeting Wednesday with President Donald Trump in response to a move by the Justice Department to pressure sanctuary cities to comply with federal immigration demands.

The protest came after the Justice Department sent letters on Wednesday to 23 state and local governments in which it threatened to subpoena them for documents proving they are cooperating with immigration officials, a requirement to keep some federal grants. The threat marked the latest effort by the administration to...