By SADIE GURMAN

WASHINGTON — Attorney General Jeff Sessions moved Thursday to again punish so-called sanctuary cities, this time threatening to deny federal crime-fighting resources to four cities beset by violence if they don’t step up efforts to help detain and deport people living in the country illegally.

The Justice Department sent letters to cities struggling with gun violence, telling them they will be ineligible for a new program that aims to root out drug trafficking and gang crime unless they give federal immigration authorities access to jails and provide advance notice before releasing someone in custody who is wanted on immigration violations. The cities — Baltimore, Albuquerque, New Mexico, and Stockton and San Bernardino in California — all expressed interest in the Justice Department’s new Public Safety Partnership, which enlists federal agents, analysts and technology to help communities find solutions to crime.

“By taking simple, common-sense considerations into account, we are encouraging every jurisdiction in this country to cooperate with federal law enforcement,” Sessions said in a statement that accompanied the letters. “That will ultimately make all of us safer — especially law enforcement on our streets.”

In the letters, the department asked the four prospective cities’ police departments to show proof of their compliance by Aug. 18.

The threat marks Sessions’ latest effort to force local authorities to cooperate with federal immigration authorities, part of a push to reduce crime he believes is linked to illegal immigration. Sessions has pledged to make fighting street crime the Justice Department’s top priority, but the strategy is putting him at odds with some city leaders, who say the best way to fight crime and build community trust is to keep local police out of federal immigration matters.

Sessions last week told jurisdictions they need to meet the same conditions or lose out on millions of dollars from a separate program that aims to send grant money to support law enforcement. That move made some local officials more defiant.

The Justice Department in June tapped 12 cities to receive aid through the Public Safety Partnership, and officials said the four cities that were sent the letters had expressed interest in the next chance at participating. Cities were chosen based on higher-than-average rates of violence and willingness to receive the help and training. Cities that want to be involved going forward will have to show they allow unfettered communication between police and federal immigration authorities, give agents access to jails in order to question immigrants, and provide them 48-hours’ notice when someone in the country illegally is about to be released.