When it comes to the artificial intelligence (AI) arms race, Microsoft (MSFT -0.18%) and Google parent Alphabet (GOOGL 1.08%) (GOOG 1.06%) are two of the frontrunners. The companies have been engaged in a fierce battle over AI in 2023, which has spanned from internet search engines to the cloud.

Microsoft launched an assault on Google Search earlier this year when it integrated the ChatGPT chatbot into its Bing search engine and threatened to transform the way consumers seek information online. Google struck back with AI initiatives of its own as it seeks to protect its dominant position in the search industry.

As a result, investors have watched Microsoft and Alphabet very closely, particularly during reporting season. Both have just released their financial results for the quarter ended June 30, and it's clear each company has unique strengths when it comes to AI. 

Here's the burning question for investors: Which stock is the better buy right now? Let's find out. 

Microsoft is weaving AI throughout its product portfolio

It's abundantly clear Microsoft is shooting for dominance when it comes to AI. It has invested a total of $13 billion into ChatGPT developer OpenAI, and the start-up's technology is now a fundamental part of Microsoft's product portfolio. As I mentioned, its Bing search engine is powered by ChatGPT, and chatbot-based search could be the future because of its ability to deliver direct answers to users' queries.

That becomes more valuable with Bing's integrations into the Microsoft Edge internet browser, because it could divert traffic away from traditional search engines like Google. Plus, Microsoft 365 (Word, Excel, PowerPoint, etc.) now features ChatGPT-powered generative AI called Copilot, which can assist users with creating text, images, and presentations. This was just released for commercial customers for a price of $30 per user per month, which opens up a new revenue stream for Microsoft's AI business.

Microsoft also offers OpenAI's latest GPT-4 technology on its Azure cloud platform to give businesses access to the most powerful AI technology available. At the end of fiscal 2023 (ended June 30), Azure OpenAI Service had 11,000 customers, up from 2,500 in just three months. That includes major companies like Mercedes Benz, which plans to install ChatGPT into 900,000 cars across the U.S. to power its voice assistant. 

The cloud could be Microsoft's most lucrative opportunity when it comes to AI, because businesses are clamoring to integrate the technology into their day-to-day operations to improve efficiency. Research firm McKinsey & Company says businesses that adopt AI today and continue developing it until 2030 could increase their free cash flow by 122%, whereas businesses that don't have an AI strategy could experience a decline instead.

Azure is quickly becoming the ultimate distribution platform for the most advanced AI tools and services, and that should go a long way to cementing Microsoft's leadership position in the industry. 

Google Search is implementing AI in more ways than one

Microsoft might be coming after Google Search with its new-look Bing, but Google still maintains a 92% global market share, and unseating that dominance won't be easy. It will become even more difficult as Google continues to improve its Bard chatbot, which is a direct competitor to ChatGPT.

But Google is also using AI to transform its traditional search engine. It recognizes the value that chatbots provide when they offer fast, direct answers to users' questions, so Google now delivers text-based responses to search queries made the regular way. It places them at the top of the page, and they could save consumers significant amounts of time that would otherwise be spent sifting through web pages looking for answers -- and that alone might keep them from jumping to competitors like Bing.

Google Search relies on advertising to generate revenue, so maintaining market share is critical. There are signs its AI-focused improvements are resonating, because it delivered 4.6% year-over-year growth in its ad revenue in the second quarter (ended June 30), which was an acceleration from its Q1 growth rate of 1.9%.

But Google Cloud was Alphabet's standout performer in Q2. It grew by 28%, which edged out key competitor Microsoft Azure by one percentage point. Google Cloud is much smaller, but the faster growth rate points to increasing market share. 

Alphabet says Google Cloud now offers the widest choice of AI supercomputers in the industry, and it has more than 80 different AI models in its portfolio. It saw a 15-fold increase in the number of customers accessing those models between April and June and, according to the company, more than 70% of generative AI unicorns (start-ups worth at least $1 billion) were Google Cloud customers in Q2.

As an added bonus, Alphabet's YouTube video streaming platform saw a return to growth during Q2. Investors should watch this segment, because YouTube is acquiring the rights to highly valuable assets like the NFL's Sunday Ticket, which could significantly boost its advertising revenue.

Microsoft vs. Alphabet: The verdict

Microsoft and Alphabet might be locked in fierce competition right now, but investors don't have to pick sides. I actually think it's worth owning both stocks given their unique strengths; Microsoft's Azure cloud business is substantially larger than Google Cloud, whereas Alphabet offers investors enormous digital advertising exposure through Google Search and YouTube.

But the two stocks are separated by one important thing: valuation. Investors rushed into Microsoft shares this year as the company integrated OpenAI's technology into its product portfolio. On the flipside, Alphabet stock lagged behind because investors perceived Microsoft's AI initiatives as a threat to its business. 

Based on the last four quarters' worth of earnings per share, Microsoft stock trades at a price-to-earnings (P/E) ratio of 34.8. Alphabet is notably cheaper, trading at a multiple of 27.9. For some perspective, the Nasdaq-100 index -- which represents the broader tech sector -- trades at a P/E ratio of 34.6. Therefore, Microsoft stock trades roughly in line with the broader market, whereas Alphabet trades at a 19% discount. 

While I think investors should own both stocks, Alphabet might be a better value than Microsoft right now.