Amazon.com Inc.’s purchase of Whole Foods Market Inc. isn’t just a $13.7 billion bet that many shoppers still want to buy groceries at physical stores. It is a direct strike at the world’s biggest retailer: Wal-Mart Stores Inc.

Wal-Mart generates more than half of its $486 billion in annual revenue from groceries and is the country’s largest grocer. Shoppers’ penchant for picking their own produce and the unprofitable nature of delivering fresh food to homes has given Wal-Mart a rare edge over Amazon and breathing room while...