Standard & Poor's on Tuesday blasted a $5 billion fraud lawsuit by the U.S. government as retaliation for its 2011 decision to strip the country of its AAA credit rating.

The McGraw Hill Financial unit was the only major credit rating agency to take away the United States' top rating and the only one sued by the Department of Justice for allegedly misleading banks and credit unions about the credibility of its ratings before the 2008 financial crisis.

In a filing with the U.S. District Court in Santa Ana, Calif., S&P said the lawsuit attempts to punish it for exercising its First Amendment free speech rights under the U.S. Constitution but also seeks "excessive fines" in violation of the Eighth Amendment.

It said the government's "impermissibly selective, punitive and meritless" lawsuit was brought "in retaliation for defendants' exercise of their free speech rights with respect to the creditworthiness of the United States of America."

(Read more: Moody's considers downgrading top US banks)

S&P seeks to dismiss the lawsuit with prejudice, meaning it cannot be brought again. The August 2011 downgrade of the U.S. credit rating to AA-plus from AAA reflected concern about Washington's ability to address the nation's swelling debt.