CHICAGO (Reuters) - Wal-Mart Stores Inc WMT.N reported better-than-expected U.S. comparable sales on Thursday, as customers stocked up on food and other supplies ahead of hurricanes and online purchases soared, sending its shares up more than 8.5 percent.

The third quarter marked Wal-Mart's strongest U.S. sales growth since 2009 despite sluggish demand and competition from Amazon.com Inc AMZN.O that has hurt brick-and-mortar rivals. The retailer has notched more than three straight years of overall comparable sales growth.

“Momentum in the business is really strong,” Wal-Mart Chief Financial Officer Brett Biggs said on an earnings conference call.

Hurricane-related sales contributed 30 to 50 basis points to overall comparable sales, the world’s largest retailer said, as Hurricanes Harvey and Irma spurred demand for food and grocery items as well as building materials.

“Food delivered its strongest quarterly performance in six years,” Wal-Mart U.S. Chief Executive Greg Foran said.

Wal-Mart has invested in its online business, cut prices and improved its in-store shopping experience by raising worker wages and making stores cleaner and more efficient.

These investments weighed on operating margins and profit, however, which both fell compared to the year-ago quarter.

Online sales soared 50 percent, exceeding growth at other big retailers but coming in below the previous quarter’s 60 percent surge.

Those sales added 80 basis points to the quarter’s comparable sales gain, boosted by walmart.com, the retailer’s online grocery delivery service and the acquisition of e-commerce startup Jet.com last year.

“Wal-Mart’s online performance continues to validate its substantial investments in this critical channel,” said Moody’s retail analyst Charlie O’Shea.

Wal-Mart forecast strong performance in the key holiday quarter and raised its full-year profit forecast. It now expects earnings per share of $4.38 to $4.46 for the fiscal year versus $4.30 to $4.40 previously.

Rival Target Corp TGT.N has also slashed prices and invested in its website and delivery, but has been less successful at translating that into sales and profit growth. Its holiday-quarter profit forecast fell short of analysts' expectations on Wednesday, sending shares down 10 percent.

The holiday shopping season can account for as much as 40 percent of a retailers’ annual sales. Wal-Mart has said it will double down on incentives and has tripled its online selections.

An employee walks out from a Walmart store in Monterrey, Mexico, April 26, 2017. REUTERS/Daniel Becerril

To compete with Amazon, Wal-Mart will offer free two-day shipping on more than two million products when the order exceeds $35 and discounts for online orders picked up at stores.

Excluding special items, earnings per share were $1 in the quarter ended Oct. 31, exceeding the average analyst estimate of 97 cents, according to Thomson Reuters I/B/E/S.

Operating income fell 6.9 percent, while operating margins slipped to 3.9 percent from 4.4 percent the same period a year earlier.

Sales at U.S. stores open at least a year rose 2.7 percent, excluding fuel price fluctuations, topping expectations for a rise of 1.7 percent, according to Consensus Metrix.

Net income dropped to $1.75 billion from $3.03 billion a year earlier due to a charge related to retiring higher-rate debt and exiting properties in international markets.

Wal-Mart said it was close to settling a years-long foreign-bribery probe and recorded a $283 million accrual charge related to a settlement.

Shares of Wal-Mart were last up 8.4 percent at $97.38. They have risen more than 30 percent so far this year.