The government complaints say S&P analysts seemed to mock their roles as gatekeepers of the financial system. The credit rating firm denies wrongdoing.

As the housing bubble was bursting in 2007, an analyst at credit rating firm Standard & Poor's made light of the situation with a song.

He went from office to office serenading co-workers with his ode to America's deepening real estate crisis. "Strong market is now much weaker, subprime is boi-ling o-ver, bringing down the house," the analyst sang to the tune of the Talking Head's "Burning Down the House."

The scene was among the details — some meant to be embarrassing — released in government lawsuits against the world's biggest credit rating firm. The complaints unveiled Tuesday by the Justice Department, and states including California, found S&P analysts seeming to mock their role as gatekeepers of the financial system, in which they are paid to grade the safety of stocks, bonds and other securities.

The Justice Department filed its civil fraud lawsuit in Los Angeles federal court and seeks to collect at least $5 billion in penalties. Several states unveiled separate lawsuits Tuesday, including one filed by California that wants the company to fork over $4 billion — four times the amount the state claims that its public pensions, such as the California Public Employees' Retirement System, lost in the toxic investments.

Government investigators gathered emails and instant messages that they said showed S&P gave rosy ratings to securities that the firm knew were ready to implode. The lawsuits claim that executives were obsessed with maintaining good relationships with the banks that paid them to analyze securities. And when those securities began to sour, they persuaded analysts to turn a blind eye to it.

One S&P analyst put it bluntly: "Let's hope we are all wealthy and retired by the time this house of cards falters."

The crackdown is the first against a major credit rating firm and is one of the most high-profile moves to hold Wall Street accountable for its role in the worst financial crisis since the Great Depression.

"It's just pure hubris — they don't really give a damn," said Charles Geisst, a Wall Street historian and professor of finance at Manhattan College. The S&P emails indicate that insiders thought "the whole process is a joke."

Standard & Poor's denied wrongdoing. The company said the government "cherry-picked" the missives and took them out of context, adding that some "are contradicted by other evidence and do not reflect our culture, integrity or how we do business."

"Claims that we deliberately kept ratings high when we knew they should be lower are simply not true," S&P said.

The release of the emails and messages shows the ferocity with which the Justice Department is going after the ratings firm. The government has been criticized for letting Wall Street firms and senior executives get off easy for their role in the crisis.

Both sides had been in negotiations up until a week ago, when talks reportedly broke down over the size of the financial penalty that S&P was being asked to pay. The government is said to have wanted a $1-billion settlement, which is more than the $911-million profit that S&P's parent, McGraw-Hill Cos., made in 2011.

Releasing potentially embarrassing internal memos has been used in the past by the government to bring other Wall Street firms back to the bargaining table.

In 2010, the Securities and Exchange Commission claimed that investment bank Goldman Sachs Group Inc. misled clients in the run-up to the financial crisis. The regulator released a trove of internal communication and documents, including over-the-top emails from a trader named Fabrice Touree. In one he boasted of selling shoddy mortgage bonds to some "widows and orphans" that he met at an airport.

For Goldman, it was a public relations nightmare made worse by its chief executive being grilled by a Senate subcommittee. The firm later settled with the government for $550 million.

"They're really taking this to the court of public opinion — to the American people," said Jeffrey Manns, a law professor at George Washington University.

The real issue facing S&P might not be how much it winds up paying to settle the lawsuits, Manns said. The bigger problem could be what kind of an admission it makes — admitting wrongdoing could invite an "avalanche" of private lawsuits that could prove financially disastrous, he said.

Going to trial isn't likely either, he said, adding that a jury would not look kindly on S&P's colorful internal communications.

At a news conference Tuesday in Washington, Atty. Gen. Eric Holder said S&P's ratings led to at least $5 billion in losses by federally insured financial institutions. The Justice Department is seeking to recover that money under the Financial Institutions Reform, Recovery and Enforcement Act, a law resulting from the savings and loan crisis of the late 1980s.