FedEx (FDX 0.59%) delivered for investors in 2020, as its shares gained 71% due in large part to the pandemic-fueled surge in residential shipments.

Those gains followed years of disappointing results, and FedEx shares are still down by nearly 10% from where they stood three years ago. Over that period, they've underperformed the S&P 500 by more than 40 percentage points.

Can FedEx continue to gain altitude in 2021, or will its share-price rally soon run out of fuel? Here's a look at what's ahead for the shipping and transportation giant.

A turnaround takes hold

Throughout much of 2019, FedEx couldn't buy a break. The company went through a very public breakup with longtime major customer Amazon, which accelerated its plan to bring a lot more of its logistics and delivery operations in-house.

The company also faced macroeconomic headwinds including Brexit and U.S.-instigated trade wars, causing earnings to underwhelm. At the same time, it was investing heavily in building out its U.S. capacity in anticipation of higher demand for consumer deliveries and as part of an expansion to provide seven-day-a-week service.

^SPX Chart

FDX vs. S&P 500 data by YCharts

That investment paid off in 2020 as the pandemic forced huge numbers of retail locations to close temporarily and increased consumer reliance on deliveries. FedEx easily topped its earnings expectations throughout the year, and experienced a holiday season that execs called "a peak like no other."

FedEx has also made progress tidying up other issues that had been weighing on it. The company's $4 billion acquisition of TNT Express in 2016 has failed to live up to expectations, as FedEx expanded in Europe just as the Continental economy was slowing. But after four long years, it's finally wrapping up the integration of TNT Express, including consolidating the business into its global network.

The drive can continue post-pandemic

The pandemic likely pulled forward some of the growth FedEx hoped to achieve from its investment in its infrastructure. But even after the stock's remarkable run-up in 2020, the ingredients are in place for it to deliver further gains.

Transportation companies head into 2021 with strong pricing power thanks to the pandemic. FedEx's ground segment in December reported its first year-over-year operating margin improvement since early 2019, and there should be further margin gains as the year goes on and Sunday deliveries allow the company to extract more productivity from its assets.

A FedEx plane on the runway.

Image source: FedEx.

Assuming the COVID-19 vaccine rollouts go as planned and there is some return to normalcy, some of the surge in business-to-consumer shipping is likely to fade. But if the economy continues to strengthen, any drop-off should be more than offset by a rise in business-to-business shipping, a segment where volumes were depressed by the pandemic, but which tends to produce higher margins than consumer shipping.

And even when brick-and-mortar retail gets back to something approaching normal, it seems likely that some of the shift to online shopping will persist. FedEx expects e-commerce package delivery volumes to grow to 111 million packages annually by 2026, up from 35 million in 2019. That's more than enough growth to offset Amazon's move to insource its delivery operations.

FedEx is trying to position itself as the go-to shipping partner for retailers not named Amazon. In pursuit of that goal, in December it acquired e-commerce platform ShopRunner, which will allow it to offer its clients a suite of Amazon Prime-like benefits.

Shippers should also benefit from the slow recovery of the airlines, which experts expect will be focused mostly on domestic travel in 2021. The curtailment of international passenger flights in 2020 meant express shippers had fewer options for air cargo transport, which boosted the pricing power of FedEx and other dedicated cargo carriers.

Is FedEx a buy?

Even after their 2020 rally, FedEx shares are still valued at a discount to archrival United Parcel Service. FedEx today trades at 14 times expected earnings and 0.8 times expected sales, compared to UPS's 18 times expected earnings and 1.6 times expected sales multiples.

There was some logic to that discount two years ago, but as FedEx has moved past its period of investment and its earnings have recovered, the valuation gap is much harder to justify. In the quarters to come, FedEx should be able to boost its free cash flow as margins improve and spending stabilizes, giving the company more flexibility to either further invest in its network or return cash to shareholders.

After sputtering for a few years, FedEx is now back in the fast lane. The momentum of 2020 should continue into this year, providing further upside for investors. Even after the stock's run-up, FedEx remains a buy today.