In the end, perseverance paid off for Bank of America (BAC) - Get Report .

The Charlotte, N.C.,-based company won a decisive victory Monday in the "Hustle" mortgage-fraud case when a federal appeals court overturned both a jury verdict and the $1.27 billion subsequently imposed by a federal judge.

Federal prosecutors failed to prove the company engaged in the kinds of fraud prohibited under the law the government's case was based on, a three-judge panel of the U.S. Court of Appeals for the 2nd Circuit ruled.

"We are pleased with the appellate court's decision," Lawrence Grayson, a bank spokesman, said in an e-mail. A call to the U.S Attorney's Office in New York wasn't answered.

The ruling marked a reversal of fortune for the government, which had chalked up a string of wins in its claim that Countrywide Financial, a troubled lender that Bank of America purchased in the buildup to the 2008 financial crisis, had defrauded investors in mortgage-backed securities.

First, a civil court jury found the government's claims were more likely true than not in late 2013.

Then, in July 2014, U.S. District Judge Jed Rakoff disagreed with the bank's contention that it shouldn't have to pay a penalty because the victims weren't harmed and the bank hadn't profited.

In a 19-page ruling, he called Countrywide's High Speed Swim Lane (HSSL), a system that dropped typical mortgage-fraud protections to speed up loan approval, "from start to finish, the vehicle for a brazen fraud by the defendants."

The case touched on behaviors at the heart of the financial crisis, which was precipitated by easy credit that helped the U.S. mortgage market to swell to as much as $15 trillion as lenders converted mortgages to lucrative securities, booking an immediate profit and transferring default risk off their own books.

When the housing bubble collapsed, however, many borrowers found themselves unable to refinance adjustable-rate loans or to afford increasing monthly payments, rendering the securities impossible to value and eventually leading to the bankruptcy of investment bank Lehman Brothers in September 2008.

That froze global credit markets, and to protect the broader economy, the government eventually provided massive bailouts of companies including Bank of America, which received $45 billion. While the bank repaid the money a year later, then-CEO Kenneth Lewis was stripped of the title of chairman by investors irritated with his costly acquisitions of both Countrywide and investment bank Merrill Lynch.

Lewis resigned at the end of 2009 and was succeeded by Brian Moynihan, who has worked to shed risky loans pre-dating the crisis and rebuild the bank's reputation and value.

From a shareholder perspective, Monday's ruling is likely to prove beneficial, since it has the potential to eliminate a drag on the company's profits.

The flaw in the government's case, the appeals court said, is that it never argued, much less proved that Countrywide intended that the mortgages bundled and sold to Fannie Mae and Freddie Mac, so-called government-sponsored enterprises, would prove to be worth less than the contracts specified.

Because the federal wire and mail fraud statutes the government's case was based on require that intention, the jury "had no legally suyfficient basis" for its verdict, the judges found.