Two mortgage lenders will pay more than $22 million combined to settle federal civil charges that they improperly foreclosed on 178 military personnel, some of whom were serving in the Iraq or Afghanistan wars.

Subsidiaries of Bank of America Corp. and Morgan Stanley failed to obtain court orders before imposing the foreclosures between 2006 and 2009, the Justice Department said Thursday. The cases will result in an average of $125,562 in payments per person. The foreclosed homes were in 22 states.

The settlement is "easily the largest amount recovered" in a case of improper military foreclosures, said Thomas E. Perez, an assistant attorney general.

"The men and women who serve our nation in the armed forces deserve, at the very least, to know that they will not have their homes taken from them wrongfully while they are bravely putting their lives on the line on behalf of their country," Perez said.

Among those foreclosed upon were several service members who had been wounded or who suffered from post-traumatic stress disorder, officials said. One involved an Iraq war veteran who was foreclosed upon while he was receiving counseling for nightmares and "nervous conditions" stemming from his service.

Under the settlement, Perez said, the lenders agreed to create additional mortgage loan protections for military personnel.

The Bank of America subsidiary, BAC Home Loans Servicing, formerly known as Countrywide Home Loans Servicing, and the Morgan Stanley subsidiary, Saxon Mortgage Services, also agreed to look into possible cases of improper foreclosures from the summer of 2009 through 2010.

The law the lenders were accused of violating, the Servicemembers' Civil Relief Act, provides protections to military personnel. Under the law, they can't be evicted and creditors can't seize their property while they're on active duty.

The Justice Department began its investigation earlier this year after separate inquiries from the U.S. Marine Corps and Sgt. James Hurley, whose home in Hartford, Mich., was foreclosed upon by Saxon in 2005 while he was in Iraq. Hurley settled with Saxon earlier this year for an undisclosed amount.

Foreclosure cases involving military personnel serving overseas began coming to light in 2005. Last month, New York-based JPMorgan Chase agreed to settle a class-action lawsuit for more than $60 million. The case involved a Marine Corps captain who said JPMorgan overcharged its military customers who took out mortgages with the bank.

Earlier this year, JPMorgan acknowledged that it had overcharged about 4,000 service members on mortgages and had wrongfully foreclosed on 14 of them. At the time, it paid $2 million to those affected and reversed the foreclosures.

Federal officials say they're working to provide greater financial protections for military families. A federal office dedicated to military financial issues, the Office of Servicemember Affairs, was launched in January and is to be incorporated within the newly created Consumer Financial Protection Bureau.