The buying frenzy for artificial intelligence (AI) stocks over the past 12 months drove many investors to Microsoft (MSFT 1.82%) and Palantir (PLTR 3.73%). Microsoft's stock rallied 65% while Palantir's stock soared more than 150%.

Microsoft gained a lot of attention because it was the biggest backer of OpenAI, the start-up that created ChatGPT. Its integration of OpenAI's generative AI tools into its own ecosystem also accelerated the growth of its cloud-based services. Palantir, which provides data mining tools for government and commercial customers, impressed investors with its expansion into the AI market and its rising profits.

But should investors buy either of these hot stocks after last year's massive gains?

A curious robot peers around a corner.

Image source: Getty Images.

Microsoft's strengths are offsetting its weaknesses

Microsoft's revenue rose 18% in its fiscal 2022 (which ended in June 2022) but only grew 7% in its fiscal 2023. The post-pandemic slowdown of the PC market curbed the growth of its Windows and Surface divisions, but it still grew its cloud-based enterprise services (Office, Dynamics, and LinkedIn) while expanding Azure -- the world's second-largest cloud infrastructure platform after Amazon Web Services (AWS).

Azure's year-over-year growth accelerated last quarter, when it grew at a faster rate than AWS. That growth was driven by the integration of OpenAI's tools into Azure. It has also been integrating those AI tools into its Bing search engine and Office 365 ecosystem to widen its moat against Alphabet's Google in the search and productivity software markets.

Meanwhile, Microsoft significantly expanded its Xbox business by acquiring video game giant Activision Blizzard in October. That acquisition should help Microsoft keep up with Sony and Nintendo in the console race while adding more titles to its Game Pass and Xbox Cloud Gaming libraries.

Analysts expect Microsoft's revenue and adjusted EPS to both rise 15% in its fiscal 2024 as its cloud business continues to grow, the PC market stabilizes, and the macro environment warms up again. Those growth rates are impressive, but the tech titan's stock isn't a screaming bargain at 34 times forward earnings.

Palantir is prioritizing its profits over its sales growth

Palantir's revenue rose 41% in 2021, but it only grew 24% in 2022 and broadly missed its own outlook for annual revenue growth of at least 30% through 2025. That slowdown was caused by the uneven timing of its government contracts, as well as macro headwinds affecting its enterprise customers. Management expects that slowdown to deepen with just 16% growth in 2023, but analysts expect its revenue will increase by 20% in 2024 as the macro environment improves.

That slower growth might dampen any hopes of Palantir becoming the next Microsoft, but it still has three clear strengths. First, its Gotham platform is widely used across the U.S. government, and Palantir continues to secure big contracts from the military and law enforcement agencies. Second, it's leveraging its battle-hardened reputation to sign up more enterprise customers for its commercial-facing Foundry platform. Lastly, Palantir's new AI Platform -- which helps its clients build their own AI apps and analyze large language models -- could widen its moat against other commercial data mining services.

Palantir's near-term sales growth might be cooling off, but it has been cutting costs and reining in its stock-based compensation to boost its profits. As a result, the company has remained profitable on a generally accepted accounting principles (GAAP) basis for four consecutive quarters -- which qualifies it for a potential inclusion in the S&P 500 index. If that happens, the stock could attract a lot more attention from big institutional investors.

Analysts expect Palantir's adjusted EPS to more than quadruple in 2023 and to rise 16% in 2024. However, its stock isn't cheap relative to those growth rates, trading at 56 times forward earnings.

The better stock buy: Microsoft

Palantir's business is stabilizing, but it still faces tough competitive and macro challenges. Microsoft is growing at a more stable rate, its stock is cheaper, and it's well diversified across the expanding AI, cloud, enterprise software, and gaming markets. Those strengths make Microsoft a better all-around investment and a more promising play on the expanding AI market.