Stocks of Rite Aid, CVS and Walgreens lost nearly $13 billion in value by midday on Thursday after Amazon announced its plan to buy online pharmacy PillPack.

Industry observers have long said it was a matter of when, not if, the retail giant would enter the health care sector — and some are saying consumers could be the real winners.

Amazon’s ubiquity in a growing number of consumer-goods categories facilitates the ability for the company to mount an immediate challenge to traditional pharmacies — and last year, Amazon obtained pharmacy distribution licenses in at least a dozen states, leading analysts to speculate at the time what the company planned to do.

“Amazon's acquisition of PillPack is a signal of continued curiosity in prescription drug fulfillment,” said Ana Gupte, senior analyst and managing director of health care services at Leerink Partners.

“They’ve been looking at this for a couple of years,” said Craig Johnson, president of the retail consulting and research firm Customer Growth Partners. A primary reason Amazon has likely stayed on the sidelines this long is it had to decide if it wanted to build this kind of business from scratch or acquire an existing provider, he said.

Experts say there’s no doubt Amazon will shake up the $400 billion pharmacy business with its purchase of Boston-based PillPack, a distributor that delivers prescriptions pre-sorted into daily doses — a convenience for the many Americans who take multiple daily medications.

“This is a sector that’s been crying out for consumer focused rationalization," said Johnson. “This nests very tightly into Amazon strategy, but it accesses nearly one-fifth of the U.S. economy. We think it’s a natural for them."

Sam Richardson, a health economist at Boston College, said: “Once again, there’s going to be a convenience factor — many people already purchase from Amazon. Yes, you can get mail-order prescription drugs now, but Amazon entering the space — this is what they do very, very well — makes it extremely convenient.”

Experts had mixed views, though, on whether this would mean lower prices on medications: As of midday Thursday, shares of Merck, Pfizer and GlaxoSmithKline were unaffected by the announcement.

“I think unless Amazon moves much more into the health care space, unless Amazon starts offering health insurance plans, I don’t see this having much of an effect on consumers besides convenience,” Richardson said.

Johnson was more optimistic, though. “Name a sector where Amazon hasn’t reduced prices,” he said. “We think this is going to be unvarnished good news for consumers.”

With the exception of the big traditional pharmacy brands, he said, “It’s a win-win for everybody.”