No company on the planet commands a greater market cap than Apple (AAPL 1.27%) right now. Only three years ago, the iPhone maker was valued below $1 trillion. Today, its market cap stands at $2.85 trillion. 

At its current pace, Apple appears to be a lock to reach $5 trillion in market cap within the next few years. But don't be surprised if it's not the first company to hit that milestone level. I predict that another stock will top $5 trillion before Apple does.

Breathing down Apple's neck

Nvidia flirted with the $1 trillion level, but there are currently only four stocks other than Apple with market caps above the $1 trillion. Two of them -- Alphabet and Amazon -- would have to grow much faster than they have recently to reach $5 trillion first.

One of the four doesn't trade on a U.S. stock exchange. Saudi Aramco's market cap is around $2.1 trillion. While it's possible the huge oil company could beat Apple to $5 trillion, I don't think it will. The demand for oil and gas simply isn't likely to increase enough to make it happen.

That leaves one contender, and it's breathing down Apple's neck. Microsoft's (MSFT 0.37%) market cap of $2.5 trillion puts it in a close second place to Apple. And as recently as late 2021, Microsoft briefly held the top spot based on market cap. 

How Microsoft could get there first

Microsoft arguably has stronger growth drivers to get it to $5 trillion than Apple does. Several of them are related to artificial intelligence (AI).

The Seattle-based tech giant's investment in OpenAI and integration of OpenAI's ChatGPT into its products have put it at the forefront of the AI boom. I don't expect Microsoft's Bing to dethrone Google Search. But it doesn't have to for Microsoft to outpace Apple.

My take is that the most important way that Microsoft will benefit from the rapid adoption of AI is with its Azure cloud services. Azure already ranks as the second-largest cloud business, behind only Amazon Web Services (AWS). Microsoft's relationship with OpenAI could enable it to gain ground on AWS. Importantly, this is a market in which Apple doesn't compete.

I also expect that Microsoft's productivity and software development tools will enjoy increased momentum thanks to AI. Organizations that use Azure will be likely to use Microsoft's other offerings as well.

However, AI isn't the only potential catalyst that could help Microsoft leap past Apple. The company already ranks as one of the top players in gaming with its Xbox system. If Microsoft's pending acquisition of Activision Blizzard clears the remaining regulatory hurdles, it should receive a bigger boost in the hot gaming market.

What could derail the prediction

Am I 100% certain that Microsoft will top $5 trillion before Apple does? No. I do think that a few things could potentially derail my prediction.

It's possible that Apple could launch one or more new products that turbocharge its growth. While I don't think the recently announced Vision Pro mixed-reality headset will be enough on its own, Apple just might have more tricks up its sleeve.

I also acknowledge that other companies could eclipse Microsoft on the AI front. Amazon and Alphabet are formidable rivals, with deep pockets and a lot of AI expertise. 

At this point, though, my bet is on Microsoft to be the first to surpass a $5 trillion market cap. And it might not take the company very long to get there.