In a retail environment that's causing trouble for many of its smaller competitors, Wal-Mart (WMT 0.07%) is shining. The company extended its long streak of comparable sales growth in the U.S. during the first quarter, and it managed to grow earnings per share despite making significant investments in its business.

The big surprise in Wal-Mart's first-quarter report was e-commerce. Online sales in the U.S soared 63% year over year, more than double the 29% growth the company managed during the fourth quarter, and more than quadruple the rate at which Amazon.com (AMZN -0.76%) grew product sales during the first quarter. Amazon is still far ahead in e-commerce, but that won't be true for long if Wal-Mart can maintain its momentum.

How did Wal-Mart do it? There were two main drivers behind the company's explosive first-quarter e-commerce growth.

A Wal-Mart box in an e-commerce fulfillment center.

Image source: Wal-Mart.

1. Acquisitions

Wal-Mart closed on the $3.3 billion acquisition of Jet.com in September of last year, so e-commerce growth was in part driven by revenue from the new addition. Jet was reportedly on pace to generate around $500 million of revenue over the next year at the time of the acquisition. Wal-Mart doesn't disclose the size of its U.S. e-commerce business, but third-party estimates put it at $13.7 billion in 2015.

Jet.com founder Marc Lore was placed in charge of Wal-Mart's entire e-commerce businesses, and he's made a few more acquisitions in recent months. Wal-Mart acquired Shoebuy, Modcloth, and Moosejaw earlier this year, and it's reportedly in talks to acquire clothing start-up Bonobos.

Wal-Mart doesn't plan to go crazy with acquisitions. According to CEO Doug McMillon, the recent acquisitions were meant to improve Wal-Mart's assortment and give it expertise in higher-margin categories like shoes and apparel. McMillon drove that point home in the conference call: "The acquisitions have received a lot of attention but our plan in e-commerce is not to buy our way to success."

Wal-Mart is focused on growing the e-commerce businesses organically, and that's what drove most of e-commerce growth during the first quarter.

2. Aggressive e-commerce initiatives

Wal-Mart stated in its earnings press release that the majority of its e-commerce growth came from organic growth through Walmart.com. This was driven by a few different initiatives. First, Wal-Mart has been increasing the number of products available on its website in an effort to catch up with Amazon. Walmart.com had 50 million different items available at the end of the first quarter, up from just 10 million one year ago. That's still far behind the hundreds of millions of items sold by Amazon, but the gap is closing.

Second, Wal-Mart introduced free two-day shipping on orders of $35 or more during the first quarter. This aggressive move prompted Amazon to slash the minimum on its own non-Prime free shipping offer twice, and it made Amazon's $99 annual Prime membership less attractive for those who care only about its free shipping benefits.

Wal-Mart also introduced pick-up discounts to customers who order certain items online and choose to pick up their order in a store. Wal-Mart is far more efficient shipping products to its stores than it is shipping individual orders to customers, allowing it to provide a sometimes-sizable discount for in-store pick-up. According to the company, 90% of the U.S. population is within 10 miles of a Wal-Mart store.

Beyond standard online sales, Wal-Mart has continued to expand its online grocery service, which allows customers to place a grocery order online and pick it up curbside at a Wal-Mart location for free. The service is now available at 670 locations in the U.S., and Wal-Mart plans to grow that number in 2017 while expanding to other countries. Online grocery sales are included in Wal-Mart's e-commerce sales figures.

Wal-Mart has finally cracked the e-commerce code

Amazon has had incredible success with its Prime membership program, offering unlimited two-day shipping, a growing catalog of streaming video, and plenty of other perks. The only way Wal-Mart can succeed online is to do what it's been doing since it was founded: offer the absolute lowest prices.

But low prices alone aren't enough. The free two-day shipping offer is critical to get customers to even consider shopping on Walmart.com, especially those used to shopping on Amazon by default. Based on Wal-Mart's first-quarter results, free two-day shipping is doing exactly that.

Wal-Mart remains a distant second behind Amazon in the race for online sales. But the company is making big strides, and if it can maintain anything close to its explosive growth rate during the first quarter, that gap will quickly shrink. Amazon certainly has something to worry about.