NEW YORK (AP) — Amazon is buying Whole Foods in a stunning move that gives it hundreds of stores across the U.S. – a brand-new laboratory for radical retail experiments that could revolutionize the way people buy groceries.

The deal valued at $13.7 billion unites the company that persuaded people to buy books – and then everything else – online with the grocery store chain that fell behind as shoppers found “good enough” alternatives to the organic and natural foods it helped popularize.

Amazon already offers grocery-delivery services in five markets, but the Whole Foods purchase would let it expand to many more. Amazon also offers grocery shipments elsewhere, but that’s tough with perishable foods.

The deal could be “transformative,” Moody’s lead retail analyst Charlie O’Shea said, “not just for food retail, but for retail in general.”

Groceries are already a fiercely competitive business, with low-cost rivals like Aldi putting pressure on traditional supermarket chains and another discounter, Lidl, opening its first U.S. stores just this week. Whole Foods itself had launched an offshoot chain named after its “365” private label brand in a nod to the popularity of no-frills chains.

The Amazon-Whole Foods combination could put even more pressure on those chains and other big grocery sellers. Walmart, which has the largest share of the U.S. food market, has been working on lowering prices, while Target has been struggling to turn around its grocery business.

“Dominant players like Walmart, Kroger, Costco, and Target now have to look over their shoulders at the Amazon train coming down the tracks,” O’Shea said.

Online delivery of groceries so far has been tough for any company to pull off because of customers’ concerns about the quality of meat and produce, Wedbush Securities analyst Michael Pachter said. But if customers know that what they are getting is the same as what they’d get at the local store, they are more likely to try it out.

Whole Foods, which will keep operating stores under its name, said in an email to customers, that it will maintain the same standards under Amazon, including bans on artificial flavors and colors and antibiotics in hens producing its eggs.

Pachter said that even if Amazon gets 20 million members of its Prime loyalty program to pay $15 a month extra for AmazonFresh grocery-delivery service, that’s 20 million not going to traditional supermarkets. He added that these are likely the higher-income households who tend to buy more expensive brands and cuts of meat.

“The conventional grocery store should feel threatened and incapable of responding,” Pachter said.

And because customers can buy foods and bulk items like toilet paper from a single retailer, discount retailers such as Costco, Target and Walmart should feel threatened, too.

Walmart has been trying to address some of those online threats, pushing harder into online to build on its strength in its stores and groceries. It announced Friday that it’s buying online men’s clothing retailer Bonobos for $310 million in cash, following a string of online acquisitions including ModCloth and Moosejaw.

Just two years ago, Whole Foods CEO John Mackey predicted disaster for Amazon’s foray into grocery delivery, telling Bloomberg BusinessWeek it would be “Amazon’s Waterloo.”

But Whole Foods has seen its sales slump and in February said it no longer saw the potential for expanding its flagship chain to 1,200 locations, up from about 460 in the United States, Canada and the United Kingdom. It also had announced a board shake-up and cost-cutting plan amid pressure from activist investor Jana Partners.

Amazon, meanwhile, has been expanding its reach in goods, services, entertainment – and groceries. It could have built up its groceries business without acquisitions, said Neil Saunders, managing director of GlobalData Retail, but that would have been costly and time-consuming.

With Whole Foods, Amazon gets an established business that it can transform through its technology and supply network expertise. And it should be able to bring cost-cutting technologies, such as robots to move inventory around, while the company gets a better picture of customers by marrying data from Amazon and Whole Foods’ loyalty programs.

That, in turn, could help Amazon do better with pricing and promotions, branding and the overall store experience, said Robert Hetu, a retail analyst at Gartner.

Amazon also has been testing automation technology at a Seattle convenience store that’s currently open only to Amazon employees. The store uses sensors to track items as shoppers put them into baskets or return them to the shelf. The shopper’s Amazon account gets automatically charged.

Hetu said Amazon isn’t likely to bring that to Whole Foods right away but could deploy pieces of it to further cut costs. Both companies said there will be no layoffs, but did not respond to other questions about Amazon’s plans for Whole Foods.

Whole Foods, founded in 1978, saw its stock peak in 2013 at $65.24. And the key measure that retailers look at to gauge their health, revenue at stores open more than a year, has fallen for seven quarters in a row.

That’s frustrated investors saddled with a drop of nearly 43 percent from the start of 2014 through Thursday, while the rest of the stock market marched 32 percent higher to record heights. The investment firm Jana Partners said in April that it had built up an ownership stake in Whole Foods because it saw ways to address its “chronic underperformance for shareholders.” Jana had pushed to shake up Whole Foods’ board of directors, among other changes.

Pressure from activist investors got so high that Mackey told Texas Monthly magazine recently that “they’re greedy bastards, and they’re putting a bunch of propaganda out there, trying to destroy my reputation and the reputation of Whole Foods, because it’s in their self-interest to do so.”

Mackey will stay as CEO, and the headquarters will stay in Austin, Texas. The deal is expected to close later this year.

© Copyright 2017 The Associated Press. All Rights Reserved. This material may not be published, broadcast, rewritten or redistributed.