Amazon agreed to buy the upscale grocery chain Whole Foods for $13.4 billion, in a deal that will instantly transform the company that pioneered online shopping into a merchant with physical outposts in hundreds of neighborhoods across the country.

The acquisition, announced Friday, is a reflection of both the sheer magnitude of the grocery business — about $800 billion in annual spending in the United States — and a desire to turn Amazon into a more frequent shopping habit by becoming a bigger player in food and beverages. After almost a decade selling groceries online, Amazon has failed to make a major dent on its own as consumers have shown a stubborn urge to buy items like fruits, vegetables and meat in person.

Buying Whole Foods also represents a major escalation in the company’s long-running battle with Walmart, the largest grocery retailer in the United States, which has been struggling to play catch-up in internet shopping. On Friday, Walmart announced a $310 million deal to acquire the internet apparel retailer Bonobos, and last year it agreed to pay $3.3 billion for Jet.com and put Jet’s chief executive, Marc Lore, in charge of Walmart’s overall e-commerce business.



“Make no mistake, Walmart under no circumstances can lose the grocery wars to Amazon,” said Brittain Ladd, a strategy and supply chain consultant who formerly worked with Amazon on its grocery business. “If Walmart loses the grocery battle to Amazon, they have no chance of ever dethroning Amazon as the largest e-commerce player in the world.”