Media playback is unsupported on your device Media caption Archive: BBC programme Requiem for Detroit, made by Julien Temple, followed people living amongst the city's ruins in 2010

A judge in the US state of Michigan has ordered the city of Detroit to withdraw its application for bankruptcy over its debts of $18bn (£12bn).

Judge Rosemarie Aquilina said the petition, filed on Thursday, violated the state's laws and constitution because it threatened pension benefits.

But the state's attorney general immediately appealed against the order.

Earlier, Governor Rick Snyder said the move towards bankruptcy would reverse decades of decay.

Bankruptcy would allow Detroit's state-appointed emergency manager, Kevyn Orr, to liquidate the city's assets to try to meet the demands of creditors and pensioners.

Analysis Really, this is all about the pensions of city workers and retirees. They and their lawyers don't object to bankruptcy per se, they just want the debt to them - their future pension rights - to be dealt with outside the "Chapter 9" bankruptcy process. That's hardly surprising since in bankruptcy, pension plans would be far down the list of people getting any of the money they are owed. Banks and bondholders would be paid long before any pensions. But since Detroit's obligation to its present and future pensioners amounts to nine of the 18 billion of its total debt, it's also easy to see why the emergency manager and state governor insist that that debt be part of Detroit's bankruptcy as well. Judge Aquilina's order was not "injunctive" which means that even if the emergency manager and governor choose to ignore it, they won't be in contempt of court. So at the very least the order delays things for days, while everyone, particularly emergency manager Kevyn Orr and Governor Rick Snyder work out how to responds to it.

Mr Orr proposed a deal in June in which creditors would accept 10 cents for every dollar they were owed.

But two pension funds representing retired city workers have resisted the bankruptcy plan, and - with tens of thousands of creditors - the city is already facing a number of lawsuits.

In her ruling on Friday, Circuit Judge Rosemarie Aquilina sided with the pension plaintiffs.

She ruled that the 2012 law which allowed for bankruptcy to be filed was unconstitutional, as it enabled the state governor to jeopardise the pension benefits of public employees.

But it remained unclear what impact the ruling would have on the proceedings.

The BBC's Jonny Dymond, in Detroit, says it is just the first stage in a multi-layer legal system, but that it throws into question the stunningly complex rescue plan for the troubled city.

Shortly after, Michigan Attorney General Bill Schuette said he had appealed against Judge Aquilina's rulings on behalf of Governor Snyder.

'Basically broke'

Detroit is the largest US city ever to file for bankruptcy. In 2012, three smaller California cities - Stockton, Mammoth Lakes and San Bernardino - took the step.

It has been struggling for decades with spiralling debts - public services are nearing collapse and about 70,000 properties lie abandoned.

Known as Motor City for its once-thriving automobile industry, Detroit stopped debt repayments to unsecured creditors last month to keep the city running.

Media playback is unsupported on your device Media caption Governor Snyder: "This has been a long period of decline. It's time to do something about it."

About $9bn of Detroit's debt is owed to the pension funds and retiree healthcare benefits of the city's 10,000 workers and 20,000 retirees.

Earlier on Friday, Gov Snyder said the city had filed for bankruptcy because it was "basically broke".

"We're the comeback state in Michigan, but to be a great state, we need Detroit on the path to being a great city again," he told Friday's news conference.

"Now is the opportunity to stop 60 years of decline," he added.

"We will come out with a stronger, better Detroit and a format to grow this city. The citizens of not just this city but the state deserve it."