Retiree Cecily McClellan talks to the media outside the federal courthouse in Detroit, on Tuesday.

DETROIT — A judge ruled Tuesday that Detroit is eligible to shed billions of dollars of its long-running debt, including the pensions of thousands of workers and retirees, in a much-anticipated decision that shifts the city’s epic bankruptcy case into a new and delicate phase.

Judge Steven Rhodes, who wondered aloud why the bankruptcy had not happened years ago, said pensions can be cut just like any contract because the Michigan Constitution does not offer bulletproof protection for employee benefits. But he signaled a desire for a measured approach and warned city officials that they must be prepared to defend any deep reductions.

“This once proud and prosperous city can’t pay its debts. It’s insolvent,” Rhodes said in announcing that Detroit was formally eligible for the largest public bankruptcy in U.S. history. “At the same time, it also has an opportunity for a fresh start.”

The ruling came more than four months after Detroit filed for Chapter 9 protection.

Rhodes agreed with unions and pension funds that the city’s emergency manager, Kevyn Orr, did not negotiate in good faith in the weeks ahead of the July filing, a key condition under federal law. But he said the number of creditors — more than 100,000 — and a wide array of competing interests probably made that “impossible.”

Detroit “could have and should have filed for bankruptcy long before it did. Perhaps years,” the judge said.

The decision set the stage for officials to confront $18 billion in debt, with a plan that might pay creditors just pennies on the dollar and is sure to include touchy negotiations over the pensions of about 23,000 retirees and 9,000 workers. Orr says pension funds are short by $3.5 billion.

Rhodes promised that he would not “lightly or casually” sign off on just any cuts.

The city has argued that it needs bankruptcy protection for the sake of beleaguered residents, who have for years tolerated slow police responses, darkened streetlights and erratic garbage pickup — a concern mentioned by the judge during a nine-day trial that ended Nov. 8.

Before the July filing, nearly 40 cents of every dollar collected by Detroit was used to pay debt, a figure that could rise to 65 cents without relief through bankruptcy, according to the city.

Orr praised the judge’s ruling and pledged to “press ahead.” He also acknowledged that pensions will be a sensitive issue because they represent a “human dimension,” with some former employees getting by on less than $20,000 a year.

The judge spoke for more than an hour in a packed courtroom, reciting Detroit’s proud history as the diverse, hard-working “Motor City” devoted to auto manufacturing. But he then tallied a list of warts: double-digit unemployment, catastrophic debt deals, thousands of vacant homes, dilapidated public-safety vehicles and wave after wave of population loss.

Behind closed doors, mediators led by another judge have been meeting with Orr’s team and creditors for weeks to explore possible settlements.

The judge has told the city to come up with a plan to exit bankruptcy by March 1. But Orr says he would like to have one ready weeks earlier.

The city is so desperate for money that it may consider selling masterpieces from the Detroit Institute of Arts as well as a water department that serves much of southeastern Michigan.