The city had applied to default on $165 million it borrowed in 2007 to pay its CalPERS pension obligations.
Creditors argued during a three-day trial last week that the city didn't do enough to straighten out its finances.
The city of Stockton owes $900 million to the California Public Employees' Retirement System to cover pension problems. CalPERS had claimed it was unfair for them to be paid 17-cents on the dollar for the loans while the retirement fund negotiated in flush times remained untouched.
Klein said the bankruptcy declaration was needed to allow the city to provide basic services.
"It's apparent to me the city would not be able to perform its obligations to its citizens on fundamental public safety as well as other basic government services without the ability to have the muscle of the contract-impairing power of federal bankruptcy law," Klein said.
The city of nearly 300,000 people has become emblematic of government excess and the financial calamity that resulted when the nation's housing bubble burst.
Its salaries, benefits and borrowing were based on anticipated long-term developer fees and increasing property tax revenue. But those were lost in a flurry of foreclosures beginning in the mid-2000s and a 70 percent decline in the city's tax base.
Karol Denniston, a municipal restructuring expert who monitored the trail, said Monday's ruling was key to cities' bankruptcy options.
The Associated Press contributed to this report.