It’s a general counsel’s worst nightmare come true. On Wednesday, New York Supreme Court Justice Eileen Bransten shot down Bank of America’s (BofA) request to exclude its CEO Brian Moynihan from testifying in a lawsuit brought by bond insurer MBIA Inc.

MBIA accused Countrywide Financial Corp., which BofA acquired in July 2008, of fraudulently inducing it to insure unsafe mortgage-backed securities. The next year, MBIA claimed BofA was liable for the mortgage lender’s conduct.

Justice Bransten decided that Moynihan could provide relevant testimony in the case given his lofty position, his previous role as president of investment banking and because he oversaw the acquisition and integration of Countrywide during that time.

“The knowledge Moynihan gained as part of the (Countrywide) Steering Committee is unique, and it is material and necessary to MBIA’s successor liability claim,” Bransten said, adding that Moynihan’s involvement in high-level decisions regarding the acquisition won’t duplicate that of any of the lower-level employees slated to testify.

BofA had argued that MBIA wanted his deposition only to harass the nation’s second-largest bank, and that its CEO had no special knowledge of the case.

This case against BofA and Countrywide is just one of many related to Countrywide and the sale of mortgage-backed securities.

In December 2011, the Department of Justice (DOJ) announced that it reached a settlement with BofA over charges that Countrywide discriminated against certain borrowers during the housing boom. The $335 million agreement marked the largest fair-lending settlement in the country’s history, the DOJ said at the time.

Earlier in December, BofA also agreed to a $315 million settlement with investors who claimed they were bilked over mortgage-backed securities offered by its Merrill Lynch unit. The deal was hailed as one of the largest-ever settlements of investor claims against banks related to toxic mortgage-backed securities.

Prior to this, in September 2011, BofA was reportedly considering having the Countrywide business unit file for bankruptcy if litigation losses threaten to topple the parent company. If BofA did so, the bank could use the threat as leverage against plaintiffs seeking refunds on bad mortgages. A Countrywide bankruptcy could halt legal proceedings and consolidate litigation into one court that would divide Countrywide’s remaining assets for creditors.

For more on Moynihan’s testimony, read Reuters. And to read more about BofA’s recent tumult, click here.