CLEVELAND, Ohio — Johnson & Johnson has reached a deal worth more than $20 million to settle its portions of Cuyahoga and Summit counties’ opioid lawsuits ahead of a trial set to begin later this month in a federal courtroom in Cleveland.

The large New Jersey-based health-care company announced Tuesday that it will pay a combined $10 million to both counties and another $5 million to cover for their legal expenses for trial preparation.

It will also donate $5.4 million to nonprofits in connection with opioid-related programs in both counties.

The agreement resolves both counties’ claims against Johnson & Johnson and its pharmaceutical wing Jannsen. The company marketed two opioid products, fentanyl patch Duragesic and the pill Nucynta ER, during the period covered by the litigation, according to court filings by the company.

Johnson & Johnson makes no admissions of liability, according to the statement. It has said its products made up less than one percent of the total number of prescription opioids that flowed into both counties as the overdose rate rose.

“The settlement allows the Company to avoid the resource demands and uncertainty of a trial as it continues to seek meaningful progress in addressing the nation’s opioid crisis,” the company said in a statement. “The Company recognizes the opioid crisis is a complex public health challenge and is working collaboratively to help communities and people in need.”

Frank Gallucci, an attorney for Cuyahoga County, said that “this settlement represents an important milestone in the litigation as it provides much needed funding for the community while also providing financial support for programs specifically addressing opioid exposed babies and their families.”

A spokeswoman Summit County did not immediately return a message seeking comment.

The settlement is the latest to be reached ahead of Oct. 21, when the first federal opioid trial in the country is set to begin. U.S. District Judge Dan Polster of Cleveland is presiding over more than 2,000 lawsuits from across the country, most of which were filed by cities and counties. Cuyahoga and Summit counties’ trial is set to be a test of how other trials may end.

Drugmakers Endo International and Allergan previously reached deals with the counties worth $11 million and $5 million, respectively. Mallinckrodt, a manufacturer of generic drugs, also reached a deal with the counties worth $30 million.

OxyContin maker Purdue Pharma also agreed to settle thousands of lawsuits it faces in state and federal courts nationwide in a package potentially worth up to $12 billion. The company filed for bankruptcy, which is part of the deal, though many state attorneys general oppose the deal.

Cuyahoga and Summit counties are seeking billions of dollars to address the problems associated with prescription painkillers, which many doctors’ patients were prescribed and used before turning to the street for cheaper heroin.

Manufacturers misleadingly downplayed the addictive nature of opioid painkillers, while distributors did not flag suspiciously large pill orders going all over the country, according to the lawsuits.

Drug companies have long denied any wrongdoing and said they followed all applicable laws and guidelines. They maintain they did not fuel the opioid epidemic.

Six companies remain as defendants for the first trial.

Polster has pushed for settlements since he was assigned to the litigation nearly two years ago.

A state court judge in Oklahoma ordered Johnson & Johnson to pay $572 million after he found the company fueled that state’s opioid crisis. The company, which took its case to trial, is appealing the verdict.