Standard & Poor's has accused the US Justice Department of filing its $5bn lawsuit against the ratings agency in retaliation for the company's downgrade of America's debt in 2011.

In its defence against the suit filed on Tuesday S&P claims: "Plaintiff [Justice Department] commenced this action in retaliation for [S&P's] exercise of their free speech rights with respect to the creditworthiness of the United States of America."

S&P attracted considerable ire in Washington in August 2011 when it downgraded the US's credit rating from AAA for the first time. The agency's lawyers said only S&P had downgraded the US's debt rating "and only S&P Ratings has been sued by the United States". In a statement, the Justice Department said S&P's allegations were "preposterous".

In February, the US sued S&P, claiming that federally insured banks and credit unions had purchased mortgage-backed assets rated highly by S&P in the belief that those ratings indicated the assets were less risky than lower-rated securities. They subsequently lost fortunes when the housing market collapsed.

Attorney general Eric Holder claimed S&P knew some $4bn of mortgage-backed securities were risky and was engaged in a scheme to defraud investors. Holder claimed S&P gave its seal of approval to assets that it knew were high risk in order to please the banks that issued them and to drum up new business.

The complaint alleged that "S&P falsely represented that its ratings were objective, independent, and uninfluenced by S&P's relationships with investment banks when, in actuality, S&P's desire for increased revenue and market share led it to favor the interests of these banks over investors."

S&P has called the claims "meritless". In the latest court filing the agency's lawyers state the "ratings opinions were independent and based upon a good faith assessment". The legal papers point out that "senior officials of the United States who were reviewing the same data that S&P Ratings was reviewing throughout 2007 proved no more prescient than S&P Ratings."

S&P's lawyers quote Federal Reserve chairman Ben Bernanke, who said in March 2007 that "the central scenario that housing will stabilise sometime during the middle of the year remains intact." Treasury secretary Hank Paulson is also quoted in the legal brief stating that the subprime loan issue was "largely contained".

S&P downgraded the US's AAA debt rating to AA+ in August 2011 following a knife-edge political fight over raising the US's debt ceiling. The unprecedented move caused investors to panic worldwide. Treasury officials attacked S&P claiming it had made a $2tn error in its calculations.

In June S&P upgraded its rating on US debt from stable to negative citing the improving economy. But the agency has stuck with its AA+ long-term rating, a notch below its top grade.