(Reuters) - A federal appeals court threw out a ruling that the U.S. government illegally bailed out insurer American International Group Inc AIG.N during the 2008 financial crisis, in a defeat for former chief executive officer Maurice "Hank" Greenberg.

FILE PHOTO: Maurice "Hank" Greenberg, former chairman of American International Group Inc., (AIG) arrives at the New York State Supreme Courthouse in Manhattan, New York City, U.S., September 29, 2016. REUTERS/Brendan McDermid

The Federal Circuit Court of Appeals in Washington said Greenberg’s Starr International Co had no legal right to challenge the bailout because that right belonged to AIG, which chose not to sue.

Tuesday’s decision by a three-judge panel was a victory for the government in a lawsuit testing its power to bail out companies, including those deemed “too big to fail.”

David Boies, Starr’s lawyer, said “we respectfully disagree” with the decision and they would appeal to the U.S. Supreme Court. The Department of Justice had no immediate comment.

AIG was rescued in September 2008 after running up huge losses from insurance on shoddy mortgage securities.

Starr said the government harmed shareholders through an unconstitutional “exaction,” by taking a 79.9 percent stake in the stricken insurer in exchange for a high-interest $85 billion loan from the Federal Reserve Bank of New York.

“While punitive measures against a corporation may ultimately be borne by its shareholders, a finding that those measures targeted shareholders directly is a wholly different matter,” Chief Judge Sharon Prost wrote for the appeals court.

“The alleged injuries to Starr are merely incidental to injuries to AIG, and any remedy would go to AIG, not Starr,” she added.

Starr had been New York-based AIG’s largest shareholder, with a 12 percent stake. It sought more than $40 billion of damages for shareholders.

In June 2015, Court of Federal Claims Judge Thomas Wheeler agreed with Starr that the New York Fed overstepped its authority in arranging the $85 billion loan, but he refused to award damages because AIG would have gone bankrupt without it.

The judge also rejected damages for a subsequent reverse stock split.

Wheeler ruled after a trial featuring testimony from former Fed chairman Ben Bernanke, and former Treasury secretaries Henry “Hank” Paulson and Tim Geithner.

Greenberg appealed Wheeler’s damages ruling. The government appealed his standing and exaction rulings.

Dennis Kelleher, CEO of nonprofit Better Markets, in an interview welcomed the decision, saying the case may help regulators address future financial system shocks “without worrying about courts second-guessing them years later.”

AIG’s bailout eventually totaled $182.3 billion but was repaid, leaving taxpayers with nearly $23 billion of profit.

Greenberg, 92, led AIG for nearly four decades before being ousted in March 2005.

The case is Starr International Co v U.S., Federal Circuit Court of Appeals, Nos. 2015-5103, 2015-5133.