Morgan Stanley agreed on Thursday to pay $102 million to end an investigation in Massachusetts into unfair lending practices.

Martha Coakley, the state's attorney general, said Morgan Stanley improperly loaned billions of dollars to subprime lender New Century which then sold loans to unqualified borrowers. Morgan Stanley also packaged these loans and sold them to big investors like pension funds.

Calling the settlement unprecedented, Coakley said the amount would be divided between homeowners, taxpayers and the state's pension fund. Morgan Stanley will pay $58 million to affected Massachusetts borrowers, $23 million to the state's pension fund to make up for the investment losses it suffered and return $19.5 million to the state's taxpayers.

Aggressive lending practices helped inflate the housing market which later crashed, paving the way to the devastating financial crisis. Massachusetts lenders were especially hard-hit by these risky practices and state and federal regulators have probed the matter aggressively here.

A Morgan Stanley spokeswoman said the bank is pleased to resolve this matter in a way that will help many Massachusetts homeowners stay in their homes.

The Morgan Stanley settlement comes roughly one year after Coakley reached a similar settlement with Goldman Sachs Group Inc , Morgan Stanley's biggest investment banking rival.

Goldman paid $60 million and the settlement marked the first time that a sub-prime loan securitizer such as an investment bank had agreed to such a deal with a state, the AG's office said at the time.

This has become an all-too-familiar pattern in which the deceptive practices of Wall Street devastated homeowners and investors, and ultimately contributed to the collapse of our economy, Coakley said in a news conference on Thursday.

Morgan Stanley should have seen many red flags, Coakley said, charging that the investment bank looked the other way and even relaxed its own standards in order to keep New Century from taking its business elsewhere.

Even as New Century spiraled toward bankruptcy, its risky lending practices exposed to the public, Morgan Stanley continued to lend money to the subprime originator, Coakley said.

(Additional reporting by Scott Malone in Boston and Steve Eder in New York, editing by Matthew Lewis)