by Steve MaraboliCNNMoneyEditor’s note: This story has been updated to include a comment from Amazon.com.
The company says the deal is for $3.1 billion.
Read moreCompanies are trying to tap into Amazon’s growing online business as it has struggled to compete with traditional retailers.
Walmart has a strong online presence, with millions of customers paying for its online shopping services and products on the website.
Its stock jumped 5% after the news was announced on Tuesday.
Its shares jumped 4.5% in afternoon trading.
In a news release, Walmart said the transaction is subject to regulatory approval, which will be made after the company completes a full review of the deal.
The deal is expected to close in the second quarter of 2019, Walmart spokesman David Johnson said.
Read MoreWalmart’s stock has surged more than 80% in 2017, when it surpassed Amazon as the world’s largest online retailer.
Walmarts stock has nearly tripled over the past three years.
Its market value has grown by more than $40 billion since 2009, according to FactSet data.
Read about Walmart’s history:Walmart first opened in 1947, and in 2012, the company started offering groceries through AmazonFresh, which is based in the United States.
Walter Block, who was the company’s president from 1991 to 2013, said the deal could give Walmart an edge on competitors, such as AmazonFresh.