Wal-Mart Stores expects U.S. e-commerce sales to surge 40 percent in the next fiscal year as its online investments allow the retail giant to play catch-up with Amazon.com.

The company also plans to add 1,000 online-grocery locations -- roughly double the current number of sites, which help fill orders from customers buying their food on Walmart.com. Total sales, meanwhile, are expected to grow at or above 3 percent, the retailer said as part of a forecast issued ahead of its shareholder meeting on Tuesday, Oct. 10.

Newsletter signup for email alerts

The upbeat guidance triggered Wal-Mart's biggest rally in more than a year, lending evidence to the view that its company-changing bet on e-commerce is beginning to pay off. Chief Executive Officer Doug McMillon has channeled more than one-third of the business's capital spending budget into digital initiatives -- like specialized e-commerce distribution centers -- up from just 20 percent a few years ago.

"It is clear that Wal-Mart intends to continue to turn up the heat online," Moody's analyst Charlie O'Shea said in a note. "We still believe Amazon's lead in online retail is insurmountable; however, Wal-Mart continues to widen the gap between itself and all other brick-and-mortar retailers."

The stock climbed as much as 4.9 percent to $84.46 on Tuesday, the biggest intraday surge since May 2016. The gain follows a 17 percent increase this year through Monday's close.

Wal-Mart's investments in e-commerce have already helped boost sales. The company expects to reach U.S. online revenue of $11.5 billion this year. The division saw increases of at least 60 percent in the past two quarters, four times the growth rate of the broader e-commerce sector.

Wal-Mart has introduced a simpler way to reorder products bought frequently, free shipping on orders of $35 or more, and discounts on thousands of items purchased online and picked up at a store.

But the online push has come at a cost: Profit margins on online orders are narrower than those for in-store sales, due to fulfillment expenses. In the second quarter, Wal-Mart's gross profit margin narrowed for the first time in two years.

The company also is teaming up with Google to let shoppers order by voice, and it said this week that it's making the returns process simpler and faster for customers who use its mobile-shopping app. It's also rolled out curbside pickup of online grocery orders in about 1,000 of its U.S. stores, putting it way ahead of rival Target, which only offers the service for nonperishable items in its hometown of Minneapolis. Wal-Mart has said that in some markets, the online grocery offering brings in customers who've never shopped at the retailer before.

As more resources go to its web operations, Wal-Mart has significantly slowed down its pace of new store development. The retailer will open fewer than 15 supercenters next fiscal year, down from about 35 additions in the current year. The Bentonville, Arkansas-based company will also develop fewer than 10 grocery-store-sized Neighborhood Markets, which have been a key driver of growth in recent years -- and a bulwark against the encroachment of German discounters Aldi and Lidl. That represents a slowdown from about 20 this year.

Outside the U.S., Wal-Mart expects to open about 255 new stores, with a focus on Mexico and China.

Wal-Mart also announced plans to buy back $20 billion in shares in fiscal 2019, which ends around January of that year. And the company reiterated its profit target for the current year, saying earnings would be $4.18 to $4.28 a share. Earnings will climb about 5 percent in fiscal 2019, also in line with previous guidance, Wal-Mart said.

"We have good momentum in the business," McMillon said in a statement. "We're executing our strategy and moving with speed to win with the customer, who is more connected than ever."

Online sales still account for a small percentage of Wal-Mart's revenue, and no one expects it to overtake Amazon in e-commerce orders. That company generated the majority of its roughly $136 billion in sales from online shopping last year.

In the second quarter, 62 percent of all U.S. internet users visited Amazon, a "remarkably high number," according to Wells Fargo analysts, illustrating just how deeply the company has penetrated the online market.

But Wal-Mart's investments should help the company maintain its lead in the grocery market, even as more customers move online, according to Moody's O'Shea.

Wal-Mart has "unmatched physical resources, including stores and supply chain, and in the process is providing consumers with a compelling online alternative to Amazon," he said.