A huge opioid settlement dragged Walgreens to a $3.7 billion loss for the first quarter, but the drugstore chain still beat Wall Street forecasts.

The company also reaffirmed its earnings forecast for the new year.

Walgreens said Thursday that it recorded a $5.2 billion, after-tax charge in the quarter that ended Nov. 30 for opioid-related litigation.

Walgreens and rival CVS Health Corp. finalized last month a settlement with state and local governments to resolve lawsuits related to opioid abuse. Opioids have been linked to more than 500,000 deaths in the United States in the past two decades.

Drugstores were subject to claims that they should have realized they were filling too many opioid prescriptions.

Not counting that charge, Walgreens adjusted earnings totaled $1.16 per share in the quarter. Sales slipped less than 2% to $33.4 billion. Analysts expect earnings of $1.14 per share on $32.89 billion in sales, according to FactSet.

Walgreens remains “firmly in the black” when not counting the legal charge, noted Neil Saunders, managing director of GlobalData. But overall, the company started the new fiscal year “with a relatively soft set of numbers,” Saunders added. He noted that much of it was expected.

Walgreens Boots Alliance Inc. runs a network of around 13,000 drugstores globally. Most of its locations are in the United States. Its stores also have become a growing source for care.

The company is working with VillageMD to open primary care practices next to some locations with the idea that drugstores and doctor offices work together to help keep patients healthy. But drugstores are still its main business.

Sales from Walgreens’ U.S. pharmacies slid 3% to $27.2 billion compared with the previous year’s quarter. A rush of COVID-19 vaccinations and testing helped results in late 2021. Strong sales of cough, cold and flu products also helped, the company said.