Investors’ lawyers hailed the decision.

“This is a first step in a decision by a federal judge that says even after the servicers’ safe harbor was enacted and even after all the wrangling in Congress, we are still going to allow people to enforce their contract rights when it is appropriate,” said Owen L. Cyrulnik, counsel at Grais & Ellsworth in New York, which is representing investors in the suit against Countrywide.

The lawsuit was filed in December after Bank of America struck a predatory lending settlement with attorneys general in 11 states. In that deal, the bank agreed to modify thousands of mortgages written by Countrywide, providing $8.4 billion in loan aid to an estimated 400,000 Countrywide borrowers.

Under the terms of the settlement, Countrywide said it would cut principal balances on some loans and reduce interest rates on others. Rates could decline to 2.5 percent, depending upon a borrower’s ability to pay, and remain at that level for five years.

But it turned out that Bank of America owned only a small portion of the mortgages it had agreed to modify. Investors who owned the largest share of the loans had not agreed to the settlement and would bear the brunt of the reduced payments.

Two investment funds holding Countrywide mortgages sued Bank of America, contending that the regulatory deal ran afoul of promises Countrywide had made when it issued the mortgage securities.

The funds, Greenwich Financial Services Distressed Mortgage Fund and QED L.L.C., are owned by Mr. Frey, who contended that the mortgage securities contained pledges by Countrywide to repurchase from investors any loans it agreed to modify. On later mortgage securities, Countrywide changed the agreements, eliminating the language about buying back modified loans.

According to the lawsuit, which is asking for a declaration from the court to make Countrywide live up to its contracts, some 374 mortgage pools issued by Countrywide contain language pledging to buy back modified loans from investors.