Stockton, Calif., emerged from bankruptcy Thursday more than two years after it entered, when a federal judge approved the city’s exit plan and allowed city retires and employees to keep their public pension benefits.

It was the third time since the bankruptcy trial ended in June that lawyers and officials gathered in hopes of a ruling in favor of the plan. The approval Thursday afternoon caused city officials to take to Twitter in celebration. Councilmember Kathy Miller tweeted a picture of her and fellow Councilmember Elbert Holman with the caption, “Whoop whoop! Stockton's BK Plan is approved! Great job Team Stockton!” Councilmember Michael Tubbs tweeted thanks to city staff, former and current councilmembers and Stockton residents.

Mayor Anthony Silva issued a more cautionary statement on his Facebook page, saying, “This is not the time to pat ourselves on the back just yet. We must not forget about the sacrifices that were made by our retirees, employees, and residents.” He added that the city spent millions in legal fees and cautioned other cities to closely monitor finances. “As Stockton begins a new chapter, we must ensure that in the future we spend taxpayers [sic] dollars more wisely.”

Attorney fees climbed north of $10 million total as Stockton was forced into a lengthy trial this spring by a single creditor that challenged the city’s exit plan. Franklin Templeton Investments said it objected to being paid 1 percent of the $35 million on its loan while Stockton is continuing to pay its full liability to the California Public Employees' Retirement System, the nation's largest public pension fund. In July, Judge Christopher Klein delayed his ruling on the case, citing a need for more information. On Oct. 1, Klein ruled that California cities may alter pensions in bankruptcy but again did not rule on Stockton’s plan. (None of the state’s three cities to enter Chapter 9 protection have attempted to impair pensions.)

In his Oct. 30 approval, Klein noted that Franklin’s recovery rate was closer to 12 percent because it was able to get back $4 million in assets on the secured portion of its claim. He also corrected Franklin’s assertion that CalPERS was Stockton’s biggest creditor. Instead, he said, that title belonged to the city’s employees, who “are the real victims of any adjustment.”

Stockton had stood its ground on the pressure to reduce its pensions, arguing that doing so would cause a mass exodus of employees and put the city at an extreme competitive disadvantage in hiring new employees. Of particular concern was the prospect of losing police officers as Stockton has struggled with skyrocketing crime rates since it laid off cops prior to filing for bankruptcy. And, although Klein’s ruling earlier this month opened the door for Stockton to leave CalPERS and create a less expensive retirement plan, city lawmakers have said that current and past city workers had already given up enough. In 2012, Stockton slashed employee salaries and decided to stop subsidizing retiree healthcare -- a cut worth $24,000 per the average retiree.

An attorney for Franklin, which argued the city’s plan is unbalanced, said at Thursday’s ruling that the firm would consider “next steps.”

Stockton, a victim of the housing market crash in 2008 and extreme spending in the early 2000s, is one of three cities in California have entered Chapter 9 protection since the 2008 recession. Vallejo filed in 2008 and exited three years later without altering pensions but did make some cuts to retiree healthcare. It still struggles with balancing its budget and fighting crime. San Bernardino entered bankruptcy about a month after Stockton did in 2012. Its case is still pending.

Tweets from The Stockton Record contributed to this article.