Wal-Mart Stores Inc. is in talks to buy online discount retailer Jet.com Inc., according to people familiar with the matter, escalating its costly quest to compete head-on with Amazon.com Inc.

A deal could give Wal-Mart’s e-commerce efforts a much-needed jolt as the world’s largest retailer seeks to grow beyond its brick-and-mortar storefronts with speedy home delivery from a network of massive suburban warehouses.

It...