WASHINGTON (AP) — Former Federal Reserve Chairman Ben Bernanke testified in federal court Thursday that insurance giant American International Group Inc. had to be rescued by the government in 2008 to avert global catastrophe.

Bernanke took the stand at a trial of a lawsuit brought by former AIG Chairman and CEO Maurice Greenberg, who is suing the government over its handling of AIG's bailout loan. Bernanke was one of the key decision makers on the bailout, which began with an $85 billion rescue loan from the New York Federal Reserve in September 2008 and grew to nearly $185 billion in federal aid.

In early questioning, Bernanke kept his answers terse when asked about the potential damage an AIG collapse might inflict and details of how the Fed came to approve the bailout. He frequently responded "yes, sir" to questions posed by Greenberg's lead attorney.

"Certainly there was an enormous amount of stress on financial institutions" in the fall of 2008 after mortgage financiers Fannie Mae and Freddie Mac had been taken over by the government and fear cascaded through financial markets, Bernanke said.

It was a rare appearance by a former Fed chairman on the witness stand. Thomas Wheeler, the judge presiding over the nonjury trial in the U.S. Court of Federal Claims, said last year he would make an exception and allowed Greenberg's lawyers to depose Bernanke because the former Fed chief has firsthand knowledge of the government's decision to bail out AIG.

Greenberg, who was AIG's biggest shareholder, is suing the federal government for about $40 billion in damages. He asserts that it violated the Constitution's Fifth Amendment by taking control of AIG without "just compensation" for the shares it received. The government took control of 80 percent of AIG's stock in exchange for the bailout aid.

New York-based AIG, which had operations around the globe, spiraled toward collapse after making huge bets on mortgage securities that soured. It has since repaid the loan, and the government says taxpayers ultimately earned $25 billion on the investment in the company.

David Boies, the attorney representing Greenberg, questioned Bernanke about a meeting of the Fed governors on Sept. 16, 2008 to approve the emergency loan to AIG, and the extent to which details of the proposed terms of the loan were discussed.

Bernanke said he couldn't recall whether specific details, such as various fees to AIG, were discussed before central bank officials voted. During a couple of hours of testimony, he appeared at least slightly annoyed and shifted several times in his chair.

The terms of the loan included the huge government stake in the company and an interest rate called "crazily high" by a government official, according to an email produced in court Wednesday.

In the days before the Fed governors voted on the loan, Bernanke said, there was concern that AIG "didn't have a clear idea" of how much it would be able to repay the government. Two years later, in September 2010, Bernanke testified before a panel investigating the crisis that AIG "did worse than I had anticipated."

He said Thursday that the AIG bailout didn't comply with time-honored principles for central bank lending to financial companies in a crisis, such as lending to companies that are cash-strapped yet still solvent and demanding valuable collateral in return.

As he had done earlier with former Treasury Secretary Timothy Geithner, Boies tried to point up contradictions in Bernanke's statements about AIG and the bailout.

On the issue of collateral, Boies cited Bernanke's 2010 testimony that AIG was looking to sell insurance subsidiaries "that have substantial value ... so it was our assessment that they had plenty of collateral to repay our loan."

Bernanke is scheduled to continue his testimony Friday.

On Tuesday and Wednesday and earlier Thursday before Bernanke's appearance, Boies had tenaciously questioned Geithner, who headed the New York Fed at the time of the AIG loan. Geithner said he and his colleagues at the Fed and the Treasury Department believed that AIG's dire financial condition was "substantially" the result of its management taking on excessive risk.

Bernanke, who stepped down in January after eight years as Fed chairman, is a fellow at the Brookings Institution think tank in Washington and has been writing a memoir. The financial crisis, which plunged the economy into the deepest recession since the 1930s, was the defining moment of his tenure. Under his leadership, the Fed invoked all its conventional tools to salvage the economy. Once those were exhausted, Bernanke turned to extraordinary steps never before tried by the Fed.

AIG became a symbol for excessive risk on Wall Street and a touchstone of public anger. It was criticized, among other things, for paying millions of dollars in bonuses to executives after it was bailed out.

On Monday Henry Paulson, a Treasury secretary under George W. Bush, testified that the AIG bailout was specifically designed by the government to punish the company. Paulson, who headed Treasury at the time of the rescue, said AIG shareholders should have faced punishment for the company's troubled balance sheet.