Four large drug companies reached a last-minute $260 million legal settlement over their role in the U.S. opioid addiction epidemic, averting the first federal trial that was scheduled to start Monday morning in Cleveland.

The settlement covers drug distributors AmerisourceBergen, Cardinal Health, and McKesson and Israel-based drugmaker Teva Pharmaceutical, and ends lawsuits by two Ohio counties.

Hunter Shklonik, an attorney for the counties, said Teva is paying $20 million in cash and will contribute $25 million worth of Suboxone, an opioid addiction treatment.

The judge overseeing Monday's trial said he would work out a new trial date for the remaining defendant, pharmacy chain operator Walgreens Boots Alliance.

On Friday, talks with the same defendants collapsed, which were aimed at reaching a broader $48 billion settlement covering thousands of lawsuits filed by counties, towns, and states from across the country over the crisis.

The trial was scheduled to pit two Ohio counties against the five companies that the local governments say helped fuel a nationwide crisis. Some 400,000 U.S. overdose deaths between 1997 and 2017 were linked to opioids, according to government data.

The report said the settlement only covered the two Ohio counties acting as plaintiffs in the so-called bellwether or test trial.

Attorneys were seen hugging and congratulating each other outside the courtroom.

This illustration image shows tablets of opioid painkiller Oxycodon delivered on medical prescription taken on September 18, 2019 in Washington, DC.

Eric Baradat | AFP | Getty Images

The outcome of the trial had been expected to help shape a broader settlement of the more than 2,300 lawsuits against a larger number of defendants, including health conglomerate Johnson & Johnson.

The settlement Monday morning comes after last-ditch efforts to strike a broader $48 billion settlement fell short on Friday.

Some 2,600 lawsuits have been brought by states, towns, cities, counties and tribal governments who say drugmakers overstated the benefits of opioids while downplaying the risks and distributors failed to flag and halt a rising tide of suspicious orders, shipping vast amounts of the pills across the country.

Drugmakers have denied wrongdoing, arguing their products carried U.S. Food and Drug Administration-approved labels that warned of the addictive risks of opioids. They say they did not cause the terrible toll the epidemic has had on states and localities.

AmerisourceBergen, Cardinal Health, and McKesson said in a joint statement on Saturday that they made up only "one component of the pharmaceutical supply chain" and their role was to make sure medicines prescribed by licensed doctors were available for patients.

"We remain deeply concerned by the impact the opioid epidemic is having on families and communities across our nation — and we're committed to being part of the solution," the statement said.

Together, the three companies distribute around 90% of the country's drugs.

'Public health disaster'

The two Ohio counties have obtained more than $60 million in prior settlements with drugmakers J&J, Endo International, Mallinckrodt, and Allergan.

Claims against smaller distributor Henry Schein by Summit County were dismissed over the weekend. Cuyahoga had not sued that company.

On Friday, U.S. Judge Dan Polster in Cleveland summoned executives from the big three distributors and Teva to court to hammer out a global deal that would have averted the trial. Polster also invited states, which have sued but do not have cases before him, to participate in settlement talks.

Polster oversees more than 2,300 of the roughly 2,600 U.S. opioid lawsuits.

After nearly 11 hours, during which Polster shuttled between plaintiffs and defendants, the talks ended without a deal.

The breakdown marked a setback for Polster, who has aggressively pushed for a settlement that "could do something meaningful to abate this crisis."

Pharmacy chains and drug distributors unsuccessfully tried to remove the outspoken judge from the case, saying he was biased and had pressed too hard for a costly settlement.

Attorney Paul Hanly told reporters on Friday that local governments he represents were not on the same page as the state attorneys general involved in the talks.

Pennsylvania Attorney General Josh Shapiro said it was profoundly disappointing that local governments would not go along with a settlement he valued at $48 billion, including $22 billion in cash and $26 billion in products and services.

Read the complete Journal report here.

CNBC contributed to this report.