Costco Wholesale (NASDAQ:COST) has been a big winner as the COVID-19 pandemic reshaped the retail landscape over the past year. Last week, the warehouse club giant reported that its sales momentum remained strong last quarter. However, earnings growth slowed dramatically, falling well short of analysts' estimates.

This earnings miss caused Costco stock to continue a recent retreat from its pandemic highs. By the end of the day on Monday, Costco shares had surrendered all of their gains of the past 12 months.

COST Chart

Costco stock performance, data by YCharts.

Investors shouldn't worry about the earnings miss, though. Costco's long-term earnings growth trajectory remains intact. That makes the recent share price slump a great buying opportunity.

Strong sales but disappointing earnings

Costco has continued to report strong sales growth in recent months, including an impressive 15.7% increase in adjusted comparable sales during January. Not surprisingly, the company also posted excellent sales results for the full second quarter of its 2021 fiscal year. Comparable sales rose 13% year over year and net sales grew 14.7% to $43.9 billion.

Offsetting this sales strength, Costco's net margin weakened to 2.17% from 2.42% a year earlier. As a result, earnings per share increased just 2% year over year, from $2.10 to $2.14, falling far short of the analyst consensus of $2.45.

Costco noted that pandemic-related costs -- mainly a $2/hour wage premium that the company began paying a year ago -- reduced EPS by about $0.41. That said, the retail giant also incurred substantial pandemic-related costs in the first quarter of fiscal 2021, which didn't stop it from ringing up a 32% jump in adjusted EPS then.

The entrance to a Costco warehouse

Image source: Costco Wholesale.

It's (almost) all about gas

Lower margins on gasoline sales drove the deterioration in Costco's profitability last quarter. Gross margin in Costco's core merchandise categories increased by about 0.7 percentage points year over year. However, overall gross margin decreased ever so slightly, mainly because gasoline margins weakened significantly in the period.

Indeed, gasoline is a big business for Costco, but it produces volatile profits. When gasoline costs are rising -- as was the case in recent months -- Costco is deliberately slow to raise its prices. This fosters customer loyalty and drives traffic to its gas stations (and, by extension, its warehouses), but it comes at the cost of profitability.

Conversely, when gasoline prices are falling, Costco tends to earn higher margins from its gas business. Thus, investors shouldn't worry about Costco's weaker profitability last quarter.

Just a blip

Going forward, there are good reasons to be optimistic about Costco's profit growth potential. In the near term, a major cost headwind just disappeared, as Costco discontinued its pandemic wage premium at the beginning of March. While the company simultaneously raised its base wage scale, it will still save hundreds of millions of dollars annually.

In the intermediate term, the recent rally in gasoline prices is likely to peter out soon, leading to better profitability from that business. Additionally, Costco is likely to increase its membership fees within the next year or two. The company tends to raise membership fees every five or six years, and the last increase came in June 2017. Membership fees account for the bulk of the warehouse club's profits, so any increase could drive a significant acceleration in earnings growth.

Looking further ahead, Costco is likely to continue gaining market share as it capitalizes on its growing member base, store closures by weaker retailers, and its new delivery capabilities for bulky goods like appliances, mattresses, and consumer electronics. That will support its profit growth over time.

Costco stock still trades at a premium valuation of 31 times its projected earnings for the current fiscal year. However, considering the company's deep moat and massive long-term growth potential, that's a premium worth paying.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.