Nvidia (NVDA 6.18%) and Microsoft (MSFT 1.82%) are two of the market's hottest artificial intelligence (AI) stocks. Nvidia's high-end GPUs are used to process complex AI tasks in data centers, while Microsoft is a leading investor in OpenAI. Microsoft has also been integrating OpenAI's generative AI tools directly into its cloud, search, and productivity tools.

Over the past three years, Nvidia's stock has soared more than 600% while Microsoft's stock has rallied just over 70%. Nvidia was clearly the better play on the booming AI market, but will it continue to outperform Microsoft over the next few years?

An android reaches into a constellation of data points.

Image source: Getty Images.

Nvidia remains the ultimate AI play

In fiscal 2024, which ended this January, Nvidia's revenue surged 126% to $60.9 billion as its adjusted earnings per share (EPS) soared 288%. That marked a dizzying acceleration from its flat revenue growth and 25% decline in adjusted EPS in fiscal 2023.

The company struggled in fiscal 2023 as the PC market's post-pandemic slowdown throttled its sales of gaming GPUs. The crypto market's meltdown exacerbated that pressure as disillusioned miners flooded the market with secondhand GPUs.

The macro headwinds also drove some companies to rein in their purchases of new data center GPUs.

But in fiscal 2024, the soaring popularity of ChatGPT and other generative AI platforms sparked a buying frenzy in its data center GPUs. Its sales of gaming GPUs also stabilized in the second half of the year as the PC and crypto markets recovered.

Nvidia generated 78% of its revenue from its data center GPUs in fiscal 2024, and the market's demand is still outstripping its supply by a wide margin. From fiscal 2024 to fiscal 2027, analysts expect its revenue to have a compound annual growth rate (CAGR) of 35% as its EPS increases at a CAGR of 39%. Those growth rates are astonishing, but its stock still doesn't look terribly expensive at 39 times forward earnings.

Nvidia seems like a simple way to profit from the growth of the generative AI market, which Fortune Business Insights estimates will have a CAGR of 47.5% from 2023 to 2030. But investors shouldn't overlook its longer-term challenges.

AMD is rolling out cheaper data center GPUs, its top cloud customers are developing their own first-party chips, and start-ups like Groq are creating faster dedicated chips to process natural language queries. Chinese chipmakers could also launch alternative AI chips to counter the export curbs on Nvidia's top-tier chips.

Microsoft is a more balanced play on the AI market

Microsoft is more diversified. Its sprawling ecosystem houses its Windows operating system, Office productivity software, Azure cloud infrastructure platform, Bing search engine, Xbox gaming business, and Surface hardware devices.

In fiscal 2023 (which ended last June), Microsoft's revenue and adjusted EPS both rose 7% as the expansion of its cloud business -- which includes Azure, Microsoft 365, and Dynamics 365 -- offset the slower growth of its Windows, Surface, and Xbox divisions, which all faced fierce headwinds as the PC and gaming markets cooled off in a post-pandemic world.

But for fiscal 2024, analysts expect Microsoft's revenue and adjusted EPS to increase 15% and 19%, respectively, as the growth of its cloud business accelerates again. That acceleration was driven by the integration of OpenAI's generative AI tools directly into Microsoft's cloud-based services.

As result, Microsoft's Azure -- the world's second-largest cloud infrastructure platform -- has been growing faster than the market leader Amazon Web Services (AWS), as well as its third-place competitor, Alphabet's Google Cloud.

From fiscal 2024 to fiscal 2026, analysts expect Microsoft's revenue to have a CAGR of 14% as its EPS increases at a CAGR of 16%. Those estimates assume its cloud business will continue to expand, the PC market will recover, and its acquisition of Activision Blizzard will significantly strengthen its Xbox gaming division.

Those growth rates suggest Microsoft is still a sound way to profit from the expansion of the cloud, AI, and gaming markets -- but its stock isn't cheap at 30 times next year's earnings. If Microsoft's cloud business loses its momentum or antitrust regulators challenge its investments in OpenAI, its valuations could decline and drive its stock lower.

The better AI play: Nvidia

Nvidia and Microsoft are both promising plays on the AI market, but Nvidia's simpler business model, higher growth rates, and more reasonable valuations make it the better buy. Nvidia's investors should keep an eye on the competitive and regulatory headwinds, but it could be years before any of those challenges limit its growth.

Until then, Nvidia will continue to sell the market's best shovels for the AI gold rush -- and it could even eclipse Microsoft's market cap in just a few years.