Pricey specialty drugs helped CVS Health cope with tobacco withdrawal and top analyst expectations in the second quarter.

But the nation’s second-largest drugstore chain also narrowed its full-year earnings outlook and issued a third-quarter forecast that fell short of Wall Street’s expectations. Its stock fell 2.5 percent in trading Tuesday.

The Woonsocket, Rhode Island, company said revenue from its biggest business, its pharmacy benefits management segment, jumped 12 percent in the second quarter to more than $24 billion, spurred in part by specialty drugs.

These complex medications treat certain forms of cancer and hepatitis C, among other conditions. They often represent treatment breakthroughs but can cost considerably more than other prescriptions. Use of these drugs is soaring, and health insurers, employers and other bill payers are relying more on companies like CVS Health to help restrain this growth. Revenue from the company’s retail drugstore segment inched up only 2 percent to $17.2 billion in part because sales from the front-end of its stores, or the area outside the pharmacy, plunged 7.8 percent, at established locations.

CVS Health runs 7,870 drugstores. The front-end figure from those stores would have been flat if CVS hadn’t pulled tobacco products from its shelves nearly a year ago. The drugstore chain actually helped profitability by dumping thin-margin tobacco products, but its executives knew they would take a sales hit because smokers often grab other products when they stop in for their next pack.

The company dropped tobacco anyway because it is trying to burnish its image as a health care services provider. The drugstore chain runs nearly 1,000 walk-in clinics in its stores and has bulked up on healthy foods and the number of health care and beauty products it provides. It also plans to expand its reach into health care with a $1.9 billion deal to purchase the pharmacy and clinic business of the retail giant Target Corp.

CEO Larry Merlo told analysts that the Target deal helps expand his company’s presence west of the Mississippi River “in a very, very capital-efficient way,” without having to build new stores.

Overall, CVS Health earnings rose 2 percent to $1.27 billion in the second quarter while revenue rose more than 7 percent to $37.17 billion.

Adjusted earnings totaled $1.22 per share, excluding costs tied to the Target deal and the company’s pending $10 billion acquisition of pharmaceutical distributor Omnicare.