The U.S. set illegal terms in demanding American International Group Inc. stock for an $85 billion bailout during the financial crisis, but that doesn’t mean AIG investors deserve compensation, a court ruled.

What began as a long-shot lawsuit by Hank Greenberg’s Starr International Co. gained credibility over years of failed government attempts to dismiss it. During an eight-week trial, Starr’s lawyer David Boies grilled Ben Bernanke, Hank Paulson and Timothy Geithner, and U.S. Court of Claims Judge Thomas Wheeler repeatedly ruled in Greenberg’s favor.

“The government’s unduly harsh treatment of AIG in comparison to other institutions seemingly was misguided and had no legitimate purpose,” Wheeler said in Monday’s decision. “The question is not whether this treatment was inequitable or unfair, but whether the government’s actions created a legal right of recovery for AIG’s shareholders.”

Wheeler’s answer was no.

Greenberg — who had sought at least $25 billion in damages for shareholders — got nothing. Though the absence of an award may temper the judge’s dramatic rebuke of the government handling of the bailout, the ruling may still limit the Federal Reserve’s ability to deal with the next crisis.

Starr sued the U.S. in November 2011, claiming the government broke the law by insisting on 80 percent of AIG stock and imposing a 14 percent interest rate on the $85 billion loan.

The government countered, saying the demands were justified since the loan was high-risk. The bailout conditions were similar to those offered AIG in a private rescue, one that fell through over doubts about its ability to repay, Kenneth Dintzer, the government’s lead lawyer, argued.

Though the bailout ballooned to $182 billion, AIG returned to the black and repaid the assistance in 2012, leaving the government with a $22.7 billion profit.

“In the end, the Achilles’ heel of Starr’s case is that, if not for the government’s intervention, AIG would have filed for bankruptcy, Wheeler said in the ruling. ‘‘In a bankruptcy proceeding, AIG’s shareholders would most likely have lost 100 percent of their stock value.”

The case is Starr International Co. v. U.S., 11-cv-779, U.S. Court of Federal Claims (Washington).

–With assistance from Tom Schoenberg in Washington.