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, which funded subprime loans throughout the country, improperly loaned billions of dollars to New Century which then sold loans to unqualified borrowers in the state. Morgan Stanley also packaged these risky 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 state pension funds.

The state is also forcing Morgan Stanley to change some of its lending practices by requiring more disclosure and demanding that the company stop funding unfair subprime loans in Massachusetts, Coakley said.

New York-based Morgan Stanley will pay $58 million to affected Massachusetts borrowers and $23 million will go into an independent fund which will then cover the losses suffered by the Massachusetts Pension Reserves Investment Trust and the Massachusetts Municipal Depository Trust funds. The state's taxpayers will receive $19.5 million, and $2 million will go to nonprofit groups that work with victims of subprime foreclosure in the state.

Massachusetts did not sue Morgan Stanley when it launched its probe. Under terms of the settlement, Morgan Stanley admitted to no wrongdoing.

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 a 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.

She said that her investigation into unfair lending practices is continuing and that Morgan Stanley will provide information and materials needed by the office's investigators.

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.

A senior Morgan Stanley banker bought loans that the company's internal due diligence team had initially rejected, Coakley said on Thursday.

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)