Mallinckrodt agreed to pay $30 million to settle allegations accusations that it helped fuel the opioid epidemic, in a bid to avoid having to participate in the first federal trial over the addictive painkillers.

The company said in a statement Friday it will pay $24 million in cash and donate $6 million in generic products, including those used to treat addiction, as part of the settlement, which will resolve a case against Mallinckrodt that is scheduled to go to trial next month in Cleveland.

More than 2,000 states and local governments in hard-hit states including Ohio, West Virginia and Kentucky have accused opioid makers, distributors and pharmacy chains of understating the risks of prescription opioids, overstating their benefits, failing to halt suspiciously large shipments, and ignoring red flags about repeated retail sales. Next month's trial is a test case involving just two Ohio counties. Among the companies facing a jury are J&J, McKesson Corp. and Teva Pharmaceutical Industries Ltd.

Some opioid makers, including Endo and Allergan Plc, have already settled. Endo agreed to pay $10 million and donate $1 million worth of drugs while Allergan agreed to pay $5 million. Purdue Pharma is preparing to file for bankruptcy as part of a plan that may include an $11.5 billion settlement to resolve all lawsuits against it, Bloomberg previously reported.

In the lawsuits, cities and states contend that executives at the company, which makes generic versions of opioid painkillers, provided lax oversight of orders for its products and took a cavalier attitude toward sales of the addictive medicines.