(Reuters) - American International Group Inc (>> American International Group Inc) won a legal victory over where a mortgage fraud lawsuit it brought against Bank of America Corp (>> Bank of America Corp) should be heard, a two-year-old case that has largely been on hold because of the dispute over venue.

The 2nd U.S. Circuit Court of Appeals on Friday agreed with AIG that the case belongs in state court, not federal court as Bank of America preferred.

It threw out an October 2011 lower court ruling that had denied AIG's bid to move the case back to the New York state court where it had begun two months earlier.

Writing for a three-judge appeals court panel, U.S. Circuit Judge Pierre Leval rejected Bank of America's argument that the case belonged in federal court under the Edge Act, a 1919 law governing international banking.

"Removal from state to federal court was not authorized by the statute," he wrote.

AIG had sued Bank of America for $10 billion.

It accused the bank and its Countrywide and Merrill Lynch units of engineering a "massive" fraud by misrepresenting the quality of more than $28 billion of residential mortgage-backed securities in 349 trusts it bought, and lying to credit rating agencies about the underlying loans.

Shares of Bank of America plunged 20.3 percent on the day the lawsuit was announced. The case is part of AIG's effort to recover from activities that it says helped trigger its near collapse in 2008, leading to $182.3 billion of federal bailouts.

It is unclear how Friday's decision affects the part of AIG's case relating to Countrywide, which has been moved to the court of U.S. District Judge Mariana Pfaelzer in Los Angeles.

Bank of America spokesman Lawrence Grayson called Friday's decision "a narrow procedural ruling." AIG spokesman Jon Diat said the insurer was pleased with the decision.

But the venue issue may not be over, because the 2nd Circuit said Bank of America may pursue an alternative argument to keep the case in federal court. Venue disputes often arise when parties expect more favourable results in particular courts.

27 LOANS

The Edge Act was adopted to help federally chartered banks compete more effectively in offshore banking. To help free those banks from extra burdens from state regulators, it lets federal courts hear lawsuits against U.S. companies over banking transactions that are international or in a U.S. territory.

In keeping the case in federal court, U.S. District Judge Barbara Jones in October 2011 recognized that a handful of the underlying home loans concerned properties in Guam, the Northern Mariana Islands, Puerto Rico and the U.S. Virgin Islands.

But AIG countered that the securities it bought were created and sold entirely in the United States. It also said that of the 1.7 million home loans underlying the trusts, just 27 involved property in U.S. territories.

Leval accepted AIG's argument, and called Bank of America's broader interpretation of the admittedly ungrammatical Edge Act statute "arbitrary and illogical."

He did not address the merits of AIG's damages claims.

Jones has left the federal bench, and U.S. District Judge Lewis Kaplan now oversees the case in Manhattan federal court.

Pfaelzer oversees a variety of litigation over the former Countrywide Financial Corp, which Bank of America bought in July 2008. Her approval is required for the bank's record $500 million settlement, announced on Wednesday, with investors who claimed Countrywide misled them into buying risky mortgage debt.

The case is American International Group Inc et al v. Bank of America Corp et al, 2nd U.S. Circuit Court of Appeals, No. 12-1640.

(Reporting by Jonathan Stempel in New York; editing by John Wallace, Gerald E. McCormick, Leslie Gevirtz and Phil Berlowitz)

By Jonathan Stempel

Stocks treated in this article : American International Group Inc, Bank of America Corp