Bank of America Corp. will pay $20 million and Morgan Stanley $2.35 million for improperly foreclosing on members of the military — some of whom were on active duty in Iraq and Afghanistan — under a settlement with the Justice Department.

The settlement with Countrywide Home Loans Servicing LP, a unit of Bank of America, is expected to be the largest ever to come out of the civil rights division of the Justice Department for violations of the Servicemembers Civil Relief Act of 2003. That law bars lenders from foreclosing on active-duty military members and caps their interest rate on all pre-existing consumer debt at 6%.

The settlement with B of A covers 160 service members who were foreclosed on without court orders from January 2006 to May 2009.

Morgan Stanley's Saxon Mortgage Services Inc. settled for $2.35 million to resolve a suit claiming it foreclosed on about 17 service members during the same period.

Both servicers agreed to set up funds to repay service members who faced wrongful foreclosures from June 2009 through 2010, the Justice Department said Thursday. The complaints allege the companies did not consistently check the military status of borrowers on whom they foreclosed through May or June 2009.

Mark Lake, a Morgan Stanley spokesman, said in an email that Saxon has "taken meaningful steps" to ensure it has appropriate policies and procedures in place to comply with the law. "We want to apologize to those military families that were affected by any mistakes made in the foreclosure process," the email said.

Terry Laughlin, an executive vice president at Bank of America, said in an emailed statement that most of the cases involved improper foreclosures by Countrywide before B of A acquired the company. "It is our responsibility to make things right," Laughlin said. "These errors are not acceptable, and we certainly regret them."

Banks claim they ran afoul of the law because they had expected service members to inform them of their military status. But the Justice Department has made it clear that the onus for checking whether a defaulted borrower is in the military falls on servicers.

Lawyers for several banks said the settlements will prompt more private lawsuits against servicers. The Office of the Comptroller of the Currency also is focused on whether mortgage servicers have implemented the proper procedures to check whether a borrower is in the military before filing a foreclosure notice, lawyers said.

Before these settlements, JPMorgan Chase & Co. was the only major servicer to take a public beating from Congress for improperly foreclosing on service members. In February, JPMorgan Chase admitted that it had improperly foreclosed on at least 18 members of the military and it received a flogging from lawmakers who claimed the bank had destroyed the lives of service members, including some who may have committed suicide, because of the stress of their financial obligations while they were fighting a war.

JPMorgan Chase told Congress that the problems were industrywide. Since then, JPMorgan Chase has identified more than a dozen service members who were improperly foreclosed on and discharged their entire mortgage debt, Tom Kelly, a Chase spokesman, said Thursday. Since those private settlements, attorneys for military members have pressed other servicers to offer the same deal of giving them their homes free and clear, lawyers said.