Bank of America Corp lost its bid to dismiss a lawsuit accusing it of reneging on promises to help borrowers modify their mortgage loans under a much-criticized federal program.

The bank, however, claimed a partial victory, citing District Judge Rya Zobel's decision to dismiss claims by borrowers who sought to participate in the two-year-old Home Affordable Modification Program, or HAMP.

Zobel nonetheless ruled that homeowners who contend they did not get modifications for which they qualified under HAMP, to avoid foreclosures, could pursue claims against Bank of America.

The complaint meticulously detailed each of these plaintiffs' compliance with loan modification conditions, but said the bank willfully failed to modify the loans, either in bad faith or for its own economic benefit, Zobel wrote. Such allegations are sufficient to let the lawsuit go forward, she added.

Zobel rejected claims by borrowers who claimed they were intended beneficiaries of HAMP but never entered the program, saying they had no contractual right to relief.

She also rejected a request to block Bank of America while the lawsuit is pending from foreclosing on 37 borrowers said to be in imminent danger of losing their homes.

In a statement, Bank of America spokeswoman Shirley Norton said the company is pleased that four of the eight counts in the complaint were dismissed.

The lawsuit combines 26 cases that had been brought in 19 states, and sought class-action status for various plaintiffs.

The Court's conclusions will likely help hundreds of thousands of families to convert temporary mortgage modification plans into permanently lower monthly payments. Tens of thousands of foreclosures are likely to be prevented, said Gary Klein, a lawyer for the plaintiffs, adding that he expects the case to get class certification quickly.

Last week, Bank of America said it would take $20 billion of charges for various mortgage matters, including over its 2008 purchase of Countrywide Financial Corp.

Like several rivals, the Charlotte, North Carolina-based bank has also been in talks with state and federal regulators to resolve claims over alleged foreclosure abuses.

HAMP was created in 2009 as a centerpiece of efforts by the Obama administration to boost the nation's housing sector.

While it provides incentives to loan servicers to encourage modifications, HAMP has been widely derided as ineffective.

Through May, 731,451 borrowers had received permanent loan modifications, far below the original goal of 3 million to 4 million.

The Republican-controlled House of Representatives voted in March to wind down the program, though the Democrat-controlled Senate is not expected to follow.

Bank of America, JPMorgan Chase and Wells Fargo & Co are the largest servicers participating in HAMP.

The case is In re: Bank of America Home Affordable Modification Program (HAMP) Contract Litigation, U.S. District Court, District of Massachusetts, No. 10-md-02193.

(Reporting by Jonathan Stempel; editing by Carol Bishopric)