Walgreens canceled its 2015 plan to buy rival drugstore chain Rite Aid Corp. on Thursday, and instead agreed to buy nearly half of Camp Hill, Pa.-based Rite Aid's 4,400 locations.

Rite Aid shares dropped 26 percent, to close Thursday at $2.89, a four-year low, as investors worried how the company would recover from falling sales.

Federal competition regulators, worried about the consolidation of the chain drugstore business, wanted Walgreens to divest many Rite Aid stores to prevent it from gaining local monopolies, complicating the proposed deal.

Suburban Chicago-based Walgreens said it will pay almost $5.18 billion for nearly 2,200 of Rite Aid's stores, plus an extra $325 million penalty for killing the deal. The news leaves Rite Aid's prospects "murky," John Ransom, managing director for health care equity research at Raymond James & Co., told clients in a report.

In the Philadelphia region, Walgreens will pick up an as-yet unannounced number of Rite Aid stores along with its Fairless Hills warehouse. Walgreens already has stores across the area and a warehouse in Easton, but hasn't yet decided on any money-saving closings, said Walgreens spokesman Michael Polzin.

Like other retailers, Rite Aid is still figuring out the best balance between warehouses and stores, CEO John Standley told investors in a conference call. Besides the warehouse on Geoffrey Road in Fairless Hills, Walgreens also will  take over Rite Aid distribution centers in Danbury, Conn., and Spartanburg, S.C., and add Rite Aid branches in the surrounding sections of the United States. In March, Walgreens closed a warehouse in Logan Township, Gloucester County, and laid off 133 workers.

UPDATE 6/30/17: "All three of the Rite Aid warehouses that Walgreens will control (after the sale) are near Walgreens warehouses," suggesting more consolidations and closings on the way, a recently retired worker at one of the warehouses told me. "The Danbury Rite Aid spot is about an hour from Walgreens' Windsor, Conn. spot. The Rite Aid Spartansburg, S.C. (warehouse) is about an hour from Walgreens'  Williamston, S.C. spot." Easton was at one point expected to replace Windsor; later rumors suggested Easton could itself close; the deal for the Fairless Hills Rite Aid site raises the undertainty.

He also notes that after Walgreens closed its former Bethlehem drug-packing site, drug supplier AmerisourceBergen opened another nearby to supply drugstores — and paid some of the same workers lower wages — another result of the drug industry's relentless concentration.. (END UPDATE)

Rite Aid has been posting "dismal" sales, wrote Kim Noland, director of junk bond research for Gimme Credit LLC in New York. In the last quarter, it reported that pharmacy sales dropped 5 percent over last year's levels. Non-drug sales were down 1.5 percent.

The company is feeling "heavy reimbursement pressure" from insurers and Medicare users, analyst Ransom warned. He noted that, as part of the Walgreens deal, Rite Aid gets a 10-year option to purchase generic drugs through Walgreens' network, which should boost sales for Chester County-based AmerisourceBergen at the expense of rival McKesson Corp.

Walgreens shares rose nearly 2 percent, to $78.37, on the news it wouldn't be taking over all of Rite Aid. In recent years, Walgreens has used the piles of cash it had saved up to buy the Duane Read drugstore chain in New York, drugstore.com, and other properties.

Shares of the Memphis-based Fred's drugstore chain, which had been poised to acquire more than 1,000 Rite Aids in case of a Walgreens merger to please government competition regulators, fell sharply, almost 23 percent, to $9.51, as the merger deal fell apart.