Walgreens has agreed to pay up to $350 million in a settlement with the U.S. Department of Justice, who accused the pharmacy of illegally filling millions of prescriptions in the last decade for opioids and other controlled substances.

The nationwide drugstore chain must pay the government at least $300 million and will owe another $50 million if the company is sold, merged, or transferred before 2032, according to the settlement reached last Friday.

The government's complaint, filed in January in the U.S. District Court for the Northern District of Illinois, alleges that Walgreens knowingly filled millions of illegal prescriptions for controlled substances between August 2012 and March 2023. These include prescriptions for excessive opioids and prescriptions filled significantly early.

“We strongly disagree with the government’s legal theory and admit no liability,” Walgreens spokesperson Fraser Engerman said in a statement. “This resolution allows us to close all opioid related litigation with federal, state, and local governments and provides us with favorable terms from a cashflow perspective while we focus on our turnaround strategy.”

Amid slumping store visits and shrinking market share, Walgreens announced it was closing 1,200 stores around the country last October. Rite Aid filed for bankruptcy at the end of 2023 as it was also dealing with losses and opioid lawsuit settlements. The U.S. Department of Justice filed a similar lawsuit against CVS in December.

The complaint says Walgreens pharmacists filled these prescriptions despite clear red flags that the prescriptions were highly likely to be invalid, and the company pressured its pharmacists to fill them quickly. The government alleges Walgreen's compliance officials ignored “substantial evidence” that its stores were filling unlawful prescriptions and withheld important information on opioid prescribers from its pharmacists.

Walgreens then allegedly sought payment for many of the invalid prescriptions through Medicare and other federal healthcare programs in violation of the False Claims Act, according to the government.

The U.S. Justice Department has moved to dismiss its complaint in light of Friday's settlement.

“Pharmacies have a legal responsibility to prescribe controlled substances in a safe and professional manner, not dispense dangerous drugs just for profit,” said Attorney General Pamela Bondi in a statement. “This Department of Justice is committed to ending the opioid crisis and holding bad actors accountable for their failure to protect patients from addiction.”

Walgreen has also entered into an agreement with the Drug Enforcement Administration to improve its compliance with rules around dispensing controlled substances, maintain policies and procedures requiring pharmacists to confirm the validity of controlled substance prescriptions, and maintain a system for blocking prescriptions from prescribers that are producing illegitimate prescriptions.

With the U.S. Department of Health and Human Services, Walgreen has agreed to establish and maintain a compliance program that includes training, board oversight, and periodic reporting to the agency regarding the pharmacy's dispensing of controlled substances.

“In the midst of the opioid crisis that has plagued our nation, we rely on pharmacies to prevent not facilitate the unlawful distribution of these potentially harmful substances,” said Norbert E. Vint, Deputy Inspector General of the U.S. Office of Personnel Management, in a statement.

The settlement resolves four cases brought by former Walgreens employee whistleblowers. In 2022, CVS and Walgreens agreed to pay more than $10 billion in a multi-state settlement of lawsuits brought against them over the toll of the opioid crisis.

Over the past eight years, drugmakers, wholesalers and pharmacies have agreed to more than $50 billion worth of settlements with governments — with most of the money required to be used to fight the opioid crisis.