LOS ANGELES — Federal agents arrested 498 people from 42 countries in a four-day nationwide operation targeting cities that United States Immigration and Customs Enforcement said give sanctuary to undocumented immigrants who have committed crimes.

ICE officials said that the sweep, Operation Safe City, which concluded Wednesday, focused on “sanctuary jurisdictions” where the agency is denied access to jails to interview suspects and where its requests to take those arrested into custody are not honored.

The operation came amid an escalating conflict between these jurisdictions and the Trump administration, which has faced several legal challenges in its efforts to mandate cooperation between local law enforcement and federal immigration authorities. The arrests this week were a stinging rebuke to sanctuary cities, several of which have passed ordinances or policies preventing full cooperation with ICE.

“Sanctuary jurisdictions that do not honor detainers or allow us access to jails and prisons are shielding criminal aliens from immigration enforcement and creating a magnet for illegal immigration,” Thomas D. Homan, the acting director of ICE, said in a statement. “As a result, ICE is forced to dedicate more resources to conduct at-large arrests in these communities.”