Drugstore chain Rite Aid will use a $2 billion purchase of EnvisionRx to stretch its reach into managing pharmacy benefits in a deal that also builds its stake in two hot growth areas, specialty pharmaceuticals and Medicare prescription drug coverage.

Shares of the nation’s third-largest drugstore chain surged Wednesday after it announced that it will pay $1.8 billion in cash and $200 million in stock for EnvisionRx, a pharmacy benefit manager, or PBM, owned by the investment firm TPG.

PBMs run prescription drug plans for customers like employers and insurers. They process mail-order prescriptions and handle bills for prescriptions filled at retail pharmacies. EnvisionRx also offers services in a growing area for prescription drug spending, specialty pharmacy, and a national Medicare prescription drug plan.

Rite Aid, which does not have a PBM business, will enter a market brimming with competition from large, national players like Express Scripts Holding Co., which serves about 85 million people, and rival drugstore operator CVS Health Corp.

But Chairman and CEO John Standley told analysts Wednesday morning that the deal was a “logical step” for a company that has gained strength over the past few years.

The Camp Hill, Pennsylvania-based company runs 4,569 drugstores, a total that trails Walgreen Co. and CVS Health. It has worked aggressively to clean up its performance by paring debt, closing underperforming stores and installing in others a new wellness theme that features more organic food and personal care products, among other items.

Wednesday’s announcement came nearly two months after Rite Aid said its fiscal third-quarter earnings jumped 47 percent in a performance that trumped Wall Street expectations.

Standley said that by pairing an established retail pharmacy network with a PBM, Rite Aid can provide more benefits that help customers manage their health better.

“The dynamics in the marketplace today are reshaping how we must serve our customers,” he said, adding that those customers now control health care decisions and are increasing their focus on cost.

The deal also gives Rite Aid stronger footing in the market for specialty drugs, complex and expensive medicines that are becoming a growing source of revenue for drugstore chains.

EnvisionRx, which is based in Twinsburg, Ohio, provides benefits for about 21 million people and serves a range of employers, including the supermarket chain Safeway. It is projected to bring in about $5 billion in revenue this year.

The boards of directors for both companies have approved the acquisition, which is expected to close in September.

Shares of Rite Aid climbed more than 9 percent, or 72 cents, to $8.30 Wednesday morning, while broader trading indexes fell slightly.

That stock price, which slipped below $1 in late 2012, soared 49 percent last year, more than quadrupling the 11.4 percent advance of the Standard & Poor’s 500 index.