U.S. pharmacy operators Walgreens Boots Alliance, Walmart Inc and Kroger Co on Tuesday faced off against the state of New Mexico in the latest trial over their alleged role in the U.S. opioid epidemic, following recent high-profile losses for pharmacies in other lawsuits.

New Mexico Attorney General Hector Balderas, in his opening statement, argued that the pharmacies were supposed to act as a "dam" against a flood of illegitimate opioid prescriptions by refusing to fill prescriptions with "red flags" that signaled abuse.

"The defendants had a legal duty, I believe, to hold back the flood and protect New Mexicans from harm," he told Judge Francis Matthew, who is presiding over the non-jury trial in the 1st Judicial Circuit of New Mexico in Santa Fe.

Dan Alberstone, another lawyer for the state, said the three companies had dispensed more than 550 million opioid pills in New Mexico from 2006 to 2019 - more than 263 for every person in the state.

John Majors, a lawyer for Walmart who delivered an opening statement in defense of all three companies, countered that pharmacists must exercise their "professional judgment" rather than relying on "mechanical application of red flags."

He said that the state would not be able to prove that pharmacists "knowingly" filled any illegitimate prescriptions.

Reuters watched the opening statements via Courtroom View Network.

The U.S. opioid epidemic has caused more than 500,000 overdose deaths over two decades, according to government data. More than 3,300 lawsuits have been filed, mostly by local governments, accusing drugmakers, distributors and pharmacy chains of fueling the crisis.

Major drugmakers and distributors have collectively agreed to pay billions of dollars to settle opioid cases against them, but pharmacies have held out.

Only two cases against pharmacies have been tried to a verdict.

One, brought by two Ohio counties, resulted in a jury verdict against Walgreens, Walmart and CVS Health Corp last year, and a judgment of more than $650 million last month.

The other, brought by San Francisco against Walgreens, resulted in a judge holding the company liable last month, though no money judgment has been decided.

Walgreens and CVS also settled mid-trial with Florida for $683 million and $484 million, respectively.

New Mexico sued the pharmacies in 2017, accusing them of creating a public nuisance by failing to stop the diversion of opioids into illegal channels. The state is seeking to make the pharmacies pay for anti-addiction programs to abate that nuisance.