The city is asking a judge to toss out new Justice Department rules that would make Chicago ineligible to apply for such grants unless it agrees to give federal immigration authorities full access to its police stations and to provide 48 hours’ notice before releasing people wanted by immigration agents.

Chicago is by no means the first municipality to defy the Trump administration’s hard line against sanctuary cities. San Francisco and Santa Clara County, Calif., won an injunction in April against a broader federal effort to deny federal funds to local governments that limit their cooperation with immigration authorities. Seattle and Richmond, Calif., among others, have also sued.

But the litigation comes at a complicated time for Chicago, which has struggled with a persistently high murder rate, strained relations between residents and the police, and frequent jabs from Mr. Trump, who has threatened to “send in the Feds” if local officials cannot tamp down the bloodshed. The particular funding itself, too, is essential, Chicago officials say, because it is aimed at solving the city’s crime problem.

In his scathing rebuke, Mr. Sessions noted Chicago’s high murder rate and said the city’s leaders, to “a degree perhaps unsurpassed by any other jurisdiction,” have “chosen deliberately and intentionally to adopt a policy that obstructs this country’s lawful immigration system.” More than 400 people have been killed in Chicago this year.

“They have demonstrated an open hostility to enforcing laws designed to protect law enforcement — federal, state and local — and reduce crime, and instead have adopted an official policy of protecting criminal aliens who prey on their own residents,” Mr. Sessions said in a statement. “The city’s leaders cannot follow some laws and ignore others and reasonably expect this horrific situation to improve.”