“This is a national crisis that demands a national solution,” said Josh Stein, the attorney general of North Carolina.

But minutes after the states’ announcement, Paul J. Hanly, Jr., a lead lawyer for the cities and counties, scorned the agreement. “The proposed deal put forth is nothing more than wishful thinking on the part of the A.G.s, who are 20 months too late to this party,” he said.

The states began filing their opioid lawsuits only relatively recently, but those by local governments were first filed years ago. The lawsuits from the two Ohio counties settled Monday are among more than 2,300 such cases that Judge Polster has been overseeing for nearly two years.

Monday’s settlement is the latest in a flurry of deals reached by drug companies to avoid that landmark federal trial, which was to serve as a test case for legal arguments and evidence.

Other companies that already reached a settlement to avoid the opening trial include Johnson & Johnson; Mallinckrodt Pharmaceuticals, one of the biggest manufacturers of generic opioids; and Purdue Pharma, which has been widely blamed for igniting the opioids crisis with misleading marketing of its drug OxyContin.

The ultimate goal of all companies is to reach a so-called global settlement to resolve the cases still on the runway in federal and state courts. Purdue reached a tentative settlement to do just that in September — a deal that involves a cash payment of up to $4.5 billion from its owners, members of the Sackler family, and a restructuring of the company into a public entity that would donate all profits to cities, counties and states to compensate for costs associated with the epidemic. But that deal is mired in a long bankruptcy court process.

With today’s agreements, the combined total so far for the two Ohio counties alone — Cuyahoga, which includes Cleveland, and Summit, which includes Akron — comes to roughly $320 million. Cuyahoga will receive 62 percent of the money, and Summit will receive 38 percent. Recently, executives from both counties announced plans to abate the local crisis, and the money has already begun to be distributed.