NEW YORK -- Moody’s Corp. has agreed to pay nearly $864 million to settle federal and state claims it gave inflated ratings to risky mortgage investments in the years leading up to the financial crisis.

The deal announced Friday was struck among the New York-based rating agency, the Justice Department and the attorneys general for 21 states and the District of Columbia.

It calls for $437.5 million to go to the Justice Department and $426.3 million to be divided among the states and the District of Columbia.

Moody’s -- along with the other two major rating agencies, Standard & Poor’s and Fitch -- were widely criticized for giving low-risk ratings to the risky mortgage securities being sold ahead of the crisis, while they reaped lucrative fees.

Get Breaking News Delivered to Your Inbox

In the settlement, the world’s second-largest credit ratings agency acknowledged that it didn’t follow its own standards in rating the risk of securities backed by home mortgages and the collateralized debt obligations that relied on their health.

The system spread the risk of mortgage defaults to banks around the globe and led to a string of financial collapses in 2008 when people began defaulting on risky subprime loans.

That caused the housing market to implode in many areas and sparked the worst U.S. recession since the Depression.

Moody’s acknowledged that it used a more lenient standard for certain financial products and didn’t make public the differences from its published standards.

“Moody’s failed to adhere to its own credit rating standards and fell short on its pledge of transparency in the run-up to the Great Recession,” Principal Deputy Associate Attorney General Bill Baer said in a statement.

Under the settlement, Moody’s agreed to a number of reforms designed to make sure its credit ratings are objective, including separating commercial and credit rating functions; ensure changes to its rating methods are independently reviewed, and ensuring that some employees aren’t compensated based on Moody’s own financial performance.

“The agreement acknowledges the considerable measures Moody’s has put in place to strengthen and promote the integrity, independence and quality of its credit ratings,” Moody’s said in a statement. “As part of the resolution, Moody’s has agreed to maintain, for the next five years, a number of existing compliance measures and to implement and maintain certain additional measures over the same period.”

The agreement comes two years after the world’s largest ratings agency, Standard & Poor’s, agreed to pay nearly $1.4 billion to settle similar allegations by the Justice Department, 19 states and the District of Columbia.

With the District of Columbia, the states involved in the settlement announced Friday are Arizona, California, Connecticut, Delaware, Idaho, Illinois, Indiana, Iowa, Kansas, Maine, Maryland, Massachusetts, Mississippi, Missouri, New Hampshire, New Jersey, North Carolina, Oregon, Pennsylvania, South Carolina and Washington.