McKinsey has agreed to pay $573m (£419m) to resolve claims it faced across the US related to its role fuelling America's opioid epidemic.
The consulting firm was under investigation for its work with Purdue Pharma, which aimed to boost sales of the addictive Oxycontin painkiller.
McKinsey maintained that its past work was "lawful" and denied wrongdoing.
But California Attorney General Xavier Becerra said the firm had been "part of a machine that... destroyed lives".
Prosecutors said McKinsey had worked on strategies to "turbocharge" Oxycontin sales, advising Purdue to increase sales calls to doctors known to be high prescribers and to "subvert" restrictions on higher dosages that authorities wanted to impose.
When officials began to take legal action against Purdue, McKinsey partners discussed deleting documents related to their work with Purdue, which started in 2004 and lasted until 2019 - more than a decade after the company pleaded guilty to misrepresenting Oxycontin's risks, they said.
"McKinsey's cynical and calculated marketing tactics helped fuel the opioid crisis by helping Purdue Pharma target those doctors they knew would overprescribe opioids," said New York Attorney General Letitia James. "They knew where the money was coming from and zeroed in on it."
Prosecutors said McKinsey also made millions of dollars helping other firms involved in the industry develop similar marketing and sales plans.
The settlement resolves probes brought by 47 states, five territories and the District of Columbia. The money is to be used to fund drug treatment and other measures aimed at addressing the crisis.
McKinsey said it had also reached separate agreements with two other states, bringing the total payout to nearly $600m.
As part of the deal announced on Thursday, McKinsey "reaffirmed" a 2019 pledge to not take on any advisory work related to opioids and said it would help to release documents to the public related to its earlier work.
McKinsey's global managing partner Kevin Sneader said the firm "chose to resolve this matter in order to provide fast, meaningful support to communities across the United States".
The firm said it had improved its risk and governance processes and had fired the two partners who discussed deleting documents related to the firm's work with Purdue, "for violating the firm's professional standards".
"We deeply regret that we did not adequately acknowledge the tragic consequences of the epidemic unfolding in our communities. With this agreement, we hope to be part of the solution to the opioid crisis in the US."
In addition to its work with Purdue, McKinsey has faced questions about its relationship with companies such as US energy firm Enron, which collapsed after an accounting scandal, as well as South African firm Trillian, which was swept up in a major corruption scandal.
In an email to staff, Mr Sneader said he expected them to set a "higher standard" of behaviour" for the consulting industry.
"Today's focus is on opioids, but we have also faced other issues that have made clear the importance of improving how we act everywhere that we operate," he said. "We must use this moment to bring further energy to the discussions we have around our values and, critically, to the actions we all take to ensure they are delivered without fail every day, everywhere."
Purdue Pharma settlement
The deal is the latest settlement to emerge from the more than 3,000 lawsuits that have been brought against drug manufacturers and other firms involved in the opioid business.
The firms, which have denied wrongdoing, are blamed for using deceptive marketing and ignoring signs of abuse, unleashing an epidemic that drove millions to addiction and claimed the lives of an estimated 450,000 people through overdose deaths from 1999 to 2018.
In October, Oxycontin-maker Purdue admitted to enabling the supply of drugs "without legitimate medical purpose", paying doctors and others illegal kickbacks to prescribe the drugs, among other claims. It agreed to pay $8.3bn.
Thousands of lawsuits against pharmacies, drug distributors and others are still pending.