Image copyright Getty Images Image caption Stockton's unemployment and violent crime rates now rank among the top in the nation.

A judge has approved the California city of Stockton's bankruptcy filing, making it the most populous US city ever to enter bankruptcy protection.

A federal judge said without bankruptcy protection, Stockton would be unable to provide basic government services.

The city of 290,000, 90 miles (144km) east of San Francisco, saw its tax base plummet in the US housing market crash.

The ruling grants Stockton protection from creditors - who opposed the filing - while it negotiates debt repayment.

Stockton's creditors - bond holders and insurers who had financed the city's debt - argued the city had not cut spending enough nor sought a tax increase to avoid bankruptcy. With the city now in bankruptcy, they may not be repaid their full principals.

But lawyers for the city said it had slashed its budget to the bone after a 70% decline in the city's tax base.

The California city first filed for bankruptcy in June 2012 after failing to come to an agreement with its creditors. The judge came to his decision on Monday after a three-day trial.

"It's unfortunate that we have been forced to spend millions of dollars, thousands of hours and almost a year on this effort," city manager Bob Deis said, referring to the fight with creditors who opposed the bankruptcy filing.

Media playback is unsupported on your device Media caption Stockton slashed its police force even as crime rates have soared

"These are valuable resources and money that could have gone toward addressing the critical safety needs of our community, restoring services, and paying our creditors."

During the housing boom, the city developed its waterfront, with a new marina and sports complex, and negotiated generous pension and healthcare benefits for city employees.

But when the housing market crashed beginning in 2008, the city's revenue sank when a rush of home foreclosures caused a dip in property taxes and developer fees.

Officials were forced to make dramatic spending cuts to patch a budget deficit - roughly $26m (£17m) this year. The city eliminated a quarter of its police officers, one third of the fire department staff and 40% of all other employees. It also cut wages and medical benefits.

Stockton's unemployment and violent crime rates now rank among the worst in the nation.

The city's case was being watched closely by other struggling US cities and towns that may also seek bankruptcy protection.

Stockton's largest debt is $900m owed to the California Public Employees' Retirement System to cover pension promises. The city has kept up with pension payments at the expense of other debt, arguing it needs a strong pension plan to retain its workforce.