Retail giant Wal-Mart (NYSE:WMT) reported solid fourth-quarter results on Tuesday, with the U.S. business producing another quarter of comparable-sales growth. But the star of the show was e-commerce as U.S. online sales soared 29% year over year, an acceleration driven by the company's investments in this business as well as the acquisition of Jet.com. E-commerce is still small relative to brick-and-mortar operations, but that won't remain true for long.

What a difference a year makes

According to the Department of Commerce, total e-commerce sales in the U.S. rose 15.1% in 2016, far faster than the 2.9% growth in total retail sales. It wasn't too long ago that Wal-Mart's e-commerce business was underperforming the broad market, losing market share despite being well behind leader Amazon.com (NASDAQ:AMZN). During the fourth quarter of fiscal 2016, which ended in January of last year, Wal-Mart's global e-commerce sales increased by just 8% on a constant currency basis.

Fiscal 2017, however, was a transformative year. After a slow start, sales growth began to pick up dramatically. Global e-commerce sales were up 7% in the first quarter, 11.8% in the second, and 20.6% in the third. Wal-Mart switched to reporting U.S. e-commerce growth in its fourth-quarter report, but it's clear that the company is making progress.

The pickup area at a Wal-Mart supercenter.

Image source: Wal-Mart.

The company made two major moves last year that helped drive this growth. The first was the continued rollout of online grocery, a service that Wal-Mart aggressively expanded in 2016 after successful, regional testing. The service allows customers to place an order online, including not only grocery items but general merchandise as well, and pick it up curbside at a Wal-Mart store, free of charge. A delivery option is also available for a small fee.

This online grocery service is now available in various cities across 31 states. The company is even testing out a concept convenience store that allows customers to pick up orders without the hassle of traveling to a supercenter. With the grocery business likely to see rapid change in the coming years, driven in part by Amazon, Wal-Mart is aiming to stay one step ahead of the competition.

The second major move was buying start-up Jet.com for $3.3 billion. Jet launched in 2015 with some notable innovations, including its "smart cart", which delivers savings to customers based on how much they buy. Prices start out low, often price-matching competitors like Amazon, and then additional savings are layered on top.

Wal-Mart paid a significant premium for Jet.com, but the acquisition accomplished two things. First, it brought Jet.com CEO Marc Lore onboard as the head of Wal-Mart's entire e-commerce business. After years of e-commerce playing second fiddle to Wal-Mart's brick-and-mortar operations, an aggressive leader was necessary.

Second, Jet.com gives Wal-Mart a brand that has a better chance of clicking with those who have no interest in shopping at Wal-Mart itself. It's unclear whether the company plans to keep the Jet.com brand alive in the long run, but I think it would be a wise move.

The downside

All of these investments in e-commerce, as well as those made in stores, have knocked down Wal-Mart's bottom line. Adjusted earnings per share was $4.32 in fiscal 2017, down from $4.59 in fiscal 2016. Wal-Mart guided for adjusted earnings between $4.20 and $4.40 per share this year, roughly flat at the midpoint.

There's no question that effectively competing with Amazon will be expensive. Margins in the online business will likely be lower than those in the store business, so earnings growth going forward will be sluggish at best. But the alternative -- not competing at all -- isn't an option in a world where retail is shifting online.

Wal-Mart's recent move to offer free two-day shipping on all orders over $35 is another aggressive step that will both hurt profitability and provide a boost to e-commerce growth. The company scrapped its Amazon Prime-like subscription program in favor of this simpler strategy, and CEO Doug McMillon noted in the conference call that the company was already seeing an uptick in its e-commerce business as a result.

Wal-Mart is no longer sitting idly by as Amazon scoops up an ever-growing share of retail sales. The company made some big moves last year that turbocharged its online efforts, and this year is off to a strong start as well. The bottom line will likely remain pressured as Wal-Mart aggressively pursues this opportunity, but the company is doing what needs to be done to remain relevant.

Timothy Green has no position in any stocks mentioned. The Motley Fool owns shares of and recommends Amazon. The Motley Fool has a disclosure policy.