By Chelsey Dulaney 

CVS Health Corp. agreed to buy pharmacy-services provider Omnicare Inc. for $10.4 billion, in a move aimed at boosting the drugstore chain's business with nursing homes and senior-living facilities.

The offer for $98 a share in cash is a 3.6% premium to Omnicare's closing price on Wednesday. The total deal is valued at $12.7 billion, when including $2.3 billion in debt.

Shares of CVS gained 1.5% to $102.75 in premarket trading, while Omnicare's shares increased 1.2% to $95.80.

CVS said the deal would increase its ability to dispense prescriptions in assisted-living and long-term-care facilities.

"The acquisition of Omnicare significantly expands our business, providing CVS Health access into a new pharmacy-dispensing channel," CVS Health Chief Executive Larry Merlo said in a news release.

The deal also increases CVS Health's presence in a rapidly growing specialty pharmacy business. Omnicare helps to market, distribute and obtain reimbursement for high-price drugs typically aimed a small patient populations. This segment represents more than a quarter of Omnicare's total revenue.

In 2014, Omnicare's specialty care segment had revenue of $1.67 billion, up 20% from the year before. Sales at the company's long-term care group added 2.6% to $4.75 billion.

CVS expects the deal will add 20 cents to its adjusted per-share earnings next year and become increasingly accretive after that. CVS also said it expects to see revenue benefits.

The deal, subject to regulatory approval, is expected to close near the end of the year.

The agreement is the latest in a string of acquisitions related to how drugs are sold and distributed. The industry also has seen merger activity among pharmacy-benefit managers, or PBMs, which negotiate for medicines on behalf of employers and health plans.

In March, UnitedHealth Group Inc. agreed to acquire Catamaran Corp., the fourth-largest pharmacy-benefit manager in the U.S. by volume of prescriptions processed, for $12.8 billion in cash. The deal was seen helping UnitedHealth to bulk up its pharmacy-benefit business amid growing concern from employers and insurers about the rising costs of cutting-edge drugs.

In February, Rite Aid Corp. agreed to buy pharmacy-benefit manager Envision Pharmaceutical Services for about $2 billion from investment firm TPG.

Write to Chelsey Dulaney at Chelsey.Dulaney@wsj.com

Access Investor Kit for CVS Caremark Corp.

Visit http://www.companyspotlight.com/partner?cp_code=P479&isin=US1266501006

Access Investor Kit for Omnicare, Inc.

Visit http://www.companyspotlight.com/partner?cp_code=P479&isin=US6819041087

Subscribe to WSJ: http://online.wsj.com?mod=djnwires