WASHINGTON (Reuters) - Former U.S. Treasury Secretary Timothy Geithner on Tuesday defended the government's rescue of American International Group Inc (>> American International Group Inc) in September 2008, saying it was necessary to prevent the country from plunging into a second Great Depression.

Geithner's comments came in testimony in the trial of a lawsuit brought by Hank Greenberg, a major AIG shareholder until the bailout and the company's chief executive until 2005. He contends the terms of the government $85 billion loan to AIG cheated its shareholders.

While few legal experts expect Greenberg's lawsuit to be successful, it has served to reopen a fraught chapter in American economic history and the outcome could shape how regulators respond to future crises.

Greenberg's lawyer, star litigator David Boies, spent much of Tuesday morning introducing emails Geithner wrote and received that discussed AIG's deteriorating condition when he served as president of the New York Federal Reserve in the chaotic days around the initial bailout offer.

Many of the emails were sent by other New York Fed officials after midnight, underscoring the round-the-clock effort the government undertook to contain the 2008 financial crisis.

Boies has sought to portray the government as making ad hoc decisions that unfairly punished AIG and is arguing that the terms the New York Fed required as part of the bailout, including a nearly 80 percent stake in the company, were illegal.

Later on Tuesday, Geithner later testified that some of the terms, including the high interest rate, were in part based on a proposal from JPMorgan Chase & Co (>> JPMorgan Chase & Co.) and Goldman Sachs Group Inc (>> Goldman Sachs Group Inc), but he said he could not remember analyzing the basis for the interest rate. The proposal came from a term sheet for a possible private sector rescue, but that rescue never materialized.

The exchange grew testier as the afternoon wore on, as Boies tried to push Geithner to say the Fed had worked to avoid an AIG shareholder vote in connection with the rescue, or that regulators had failed to follow up on legitimate private sector efforts to help AIG. Geithner responded that he did not know about efforts related to shareholder votes and that he would have seriously considered any realistic proposals from private investors.

Greenberg through his Starr International Co, which was AIG's largest shareholder with a 12 percent stake, sued in 2011 seeking more than $25 billion in damages.

"EFFECTIVELY WIPED OUT"

Geithner took the stand on the seventh day of the trial, one day after his predecessor as Treasury secretary, Hank Paulson, told the same courtroom that AIG shareholders were singled out for punishment but that such terms were necessary to protect against others taking reckless risks.

On Tuesday, Boies spent time reading aloud comments Geithner made in a book he wrote about the 2008 financial crisis called "Stress Test," focusing on the consequences AIG's collapse could have on the broader financial system.

"It sounds like you are quoting me," Geithner said on multiple occasions after hearing a passage from Boies, who cited the book with enough frequency that the judge overseeing the case asked if he should go get his own copy at Barnes & Noble (>> Barnes & Noble, Inc.).

The trial is unfolding before Judge Thomas Wheeler of the U.S. Court of Federal Claims in Washington, who will decide the case.

Geithner, who appeared relaxed but whose answers grew shorter and more deliberate later in the afternoon, did attempt to walk back some comments he had made in the past about the AIG bailout, including statements that the insurance company's shareholders had been "effectively wiped out" and that the government had essentially "nationalized" AIG.

That was "not the most precise language," he said, to laughter in the courtroom.

Geithner is expected to continue his testimony on Wednesday, when government lawyers will have an opportunity to question him.

(Reporting by Aruna Viswanatha; Editing by Steve Orlofsky)

By Aruna Viswanatha