WASHINGTON — When Maurice R. Greenberg, the former chief executive of the American International Group, brought a class-action lawsuit against the government in 2011, contending that the Federal Reserve overstepped its bounds when it bailed out his company at the height of the financial crisis, the reaction was mainly befuddlement and outright ridicule.

When the case went to trial last fall, many legal experts predicted a lost cause, while both the government’s lawyers and elected officials were even more blunt: calling Mr. Greenberg an “ingrate” and the lawsuit, which demanded as much as $40 billion, an embarrassment.

But as the bench trial unfolded over nearly two months, Mr. Greenberg’s legal team, led by the prominent litigator David Boies, kept chipping away at witness after witness in pursuit of its own thesis: that the Fed had acted beyond its legal authority. By the time the trial concluded, many legal experts had moved the case from a slam-dunk for the government to too close to call. It would all depend on Judge Thomas C. Wheeler of the United States Court of Federal Claims.

On Monday, Judge Wheeler handed down his decision — a split judgment that in many ways agreed with both sides’ main points of contention. Yes, he ruled, the Fed had indeed crossed the legal line by demanding a 79.9 percent equity stake in A.I.G. as a condition of the bailout in 2008. But at the same time, the government was also correct that A.I.G. shareholders had not been damaged; in fact, they had been saved from bankruptcy and certain doom. He declined to award any damages.