The lawsuit culminates a massive, multi-year federal investigation code-named "Alchemy," but it's only the start of a more public legal battle joined by at least 16 state attorneys general.
The outcome could make or break the reputation of the world's largest credit-rating agency. It will shed additional light on how S&P and two other credit-rating agencies contributed to the nation's financial near-meltdown in 2008.
According to the lawsuit, S&P gave high marks to the investments because it wanted to earn more business from the banks that issued them.
"This alleged conduct is egregious and it goes to the very heart of the recent financial crisis," Attorney General Eric Holder said at a news conference.
Experts said the lawsuit could serve as a template for future action against Fitch and Moody's, the other two major credit rating agencies.
Critics complained that the government's action Tuesday involves civil rather than criminal charges. Criminal charges, which would carry the possibility of jail time, would be harder to prove.
Former Sen. Ted Kaufman, D-Del., who served on a panel that investigated the financial crisis, argued that actions by S&P and its employees amounted to criminal fraud.
"If you're selling something that you're saying has a certain level of safety, and you know it doesn't have that level of safety, that's fraud," Kaufman said.
He said big civil fines just end up hurting shareholders.
High ratings from the three agencies made it possible for banks to sell trillions in risky investments. Some investors, including pension funds, can buy only securities that carry high credit ratings.
S&P, a unit of New York-based McGraw-Hill Cos., called the lawsuit "meritless."
"Hindsight is no basis to take legal action against the good-faith opinions of professionals," the company said in a statement. "Claims that we deliberately kept ratings high when we knew they should be lower are simply not true."
According to the lawsuit, S&P recognized that home prices were sinking and that borrowers were having trouble repaying loans. Yet these facts weren't reflected in the safe ratings S&P gave to complex real-estate investments known as mortgage-backed securities and collateralized debt obligations, the lawsuit alleges.
At least one S&P executive who had raised concerns about the company's proposed methods for rating investments was ignored.
S&P executives expressed concern that lowering the ratings on some investments would anger the clients selling these investments and drive new business to S&P's rivals, the government claims.
The $5 billion in penalties the government is demanding would amount to several times the annual revenue of McGraw-Hill's Standard & Poor's Ratings division. The ratings business generated $1.77 billion in revenue in 2011. McGraw-Hill's total revenue was $6.25 billion.
The fraudulent ratings contributed to the failure of a California credit union that required a multibillion-dollar government bailout, the lawsuit said. It said Western Federal Corporate Credit Union bought the investments because of S&P's endorsement.
Western Federal was among five wholesale credit unions that regulators took over in 2009 and 2010. To wind them down, the National Credit Union Administration borrowed $11.2 billion from the Treasury. It's repaid about $6.1 billion. The agency said the costs will be paid by the credit union industry and Treasury will be fully repaid.
A lack of stronger evidence probably prevented Justice from seeking criminal charges against the company or its employees, said Jacob Frenkel, a lawyer formerly with the Securities and Exchange Commission.
Still, the complexity of the case could make it a model for future lawsuits against the other rating agencies, he said.
"I think the S&P case is likely to be a template for use against the other rating agencies as long as the government believes it has the evidence to make its case," Frenkel said.
Joining the Justice Department in the announcement were attorneys general from California, Connecticut, Delaware, the District of Columbia, Illinois, Iowa and Mississippi, who have filed or will file separate, similar civil fraud lawsuits against S&P. Connecticut Attorney General George Jepsen said that by the end of Tuesday, 16 states and D.C. will have sued S&P.
According to the lawsuit, S&P didn't issue a mass downgrade of subprime-backed securities until mid-2007, even though it knew in 2006 that many borrowers were struggling or failing to make payments.
The mortgages were faring so poorly "that analysts initially thought the data contained typographical errors," according to the lawsuit.
In a 2007 email, another analyst said some at S&P wanted to downgrade mortgage investments earlier, "before this thing started blowing up. But the leadership was concerned of p(asterisk)ssing off too many clients and jumping the gun ahead of Fitch and Moody's."
The complaint includes a trove of embarrassing emails and other evidence that S&P analysts recognized the market's problems early.
In 2007, for example, an analyst who was reviewing mortgage bundles forwarded a video of himself singing and dancing to a song written to the tune of "Burning Down the House": "Going all the way down, with/Subprime mortgages." The video showed colleagues laughing at his performance.
Critics have long argued that the rating agencies operate with a conflict of interest: They're paid by the banks that create the investments they're rating. If one agency appeared too strict, banks could shop around for a better rating.
S&P typically charged up to $150,000 for rating a subprime mortgage-backed security and up to $750,000 for certain other securities, the lawsuit says. If S&P lost the business to Fitch or Moody's, its main rivals, the analyst who issued the rating would have to submit a "lost deal" memo explaining why he or she lost the business.
An analyst complained in 2004 that S&P had lost a deal because its standards for a rating were stricter than Moody's. "We need to address this now in preparation for the future deals," the analyst wrote.
The documents "make clear that the company regularly would 'tweak,' 'bend,' delay updating or otherwise adjust its ratings models to suit the company's business needs," said acting Associate Attorney General Tony West.
S&P countered that the emails were "cherry picked," that they were "taken out of context, are contradicted by other evidence, and do not reflect our culture, integrity or how we do business."
It said analysts' concerns were addressed before a rating was issued and that the government left out important context.
The ratings "reflected our current best judgments," S&P said in its statement. It noted that other agencies gave the same high ratings and said the government also failed to predict the subprime mortgage crisis.
The lawsuit comes just 18 months after S&P cut its rating on long-term U.S. government debt by a notch. The downgrade followed a contentious debate between the White House and Congress over the raising of the government's borrowing limit that was resolved at the last hour.
Holder was asked about a possible link between the lawsuit and the downgrade.
"There's no connection," Holder said. He added that the department's investigation began in 2009.
But Michael Robinson, a former communications official at the SEC, said that while all three major rating agencies have lost credibility since the financial crisis, S&P's downgrade of U.S. debt put a bull's-eye on its back.
"Once you get on the government's radar, it's hard to get off scot-free," Robinson said.
The government charged S&P under a law intended to make sure banks invest safely. If S&P is found to have committed civil violations, it could face not only fines but also limits on how it does business.
McGraw-Hill shares closed down nearly 11 percent Tuesday. On Monday, after the lawsuit was first reported, they plunged nearly 14 percent.
Shares of Moody's Corp., the parent of Moody's Investors Service, another rating agency, lost nearly 9 percent Tuesday after closing down nearly 11 percent Monday.
Biggest civil settlements for Justice Dept.
1. GlaxoSmithKline - $3 billion - July 2012
2. Pfizer Inc. - $2.3 billion - September 2009
3. Columbia/HCA I and II - $1.7 billion - December 2000 and June 2003
4. Abbott Laboratories - $1.5 billion - May 2012
5. Eli Lilly and Co. - $1.4 billion - January 2009
6. Merck Sharp & Dohme - $950 million - November 2011
7. Tenet Healthcare Corp. - $923 million - June 2006
8. TAP Pharmaceuticals - $875 million - October 2001
9. GlaxoSmithKline - $750 million - October 2010
10. Serono SA - $704 million - October 2005