The software company has found stability under CEO Satya Nadella by focusing on software and services over the internet, or the cloud, with long-term business contracts.
Microsoft's big bet on cloud computing is paying off as the company has surpassed Apple as the world's most valuable publicly traded company.
The software maker's prospects looked bleak just a few years ago, as licenses for the company's Windows system fell with a sharp drop in sales of personal computers.
But under CEO Satya Nadella, Microsoft has found stability by focusing on software and services over the internet, or the cloud, with long-term business contracts.
That 1990s personal-computing powerhouse is now having a renaissance moment, as it eclipses Facebook, Google, Amazon and the other tech darlings of the late decade.
Apple had been the world's most prosperous firm since claiming the top spot from Exxon Mobil earlier this decade. Microsoft surpassed Apple briefly a few times this week, but didn't close on top until Friday, with a market value of $851 billion to Apple's $847 billion. Microsoft hadn't been at the top since the height of the dot-com boom in 2000.
Microsoft became a contender again in large part because Apple's stock fell nearly 20 percent in November, while Microsoft hasn't done any worse than the rest of the stock market. But the fact that it hasn't done poorly is a reflection of its steady focus on business customers in recent years.
Microsoft lost its lustre as people were shunning PCs in favour of smartphones. In 2013, PC sales plunged 10 percent to about 315 million, the worst year-to-year drop ever, according to research firms Gartner and IDC. It didn't help that Microsoft's effort to make PCs more like phones, Windows 8, was widely panned.
But a turnaround began when the Redmond, Washington, company promoted Nadella as CEO in 2014. He succeeded Microsoft's longtime CEO, Steve Ballmer, who initially scoffed at the notion that people would be willing to pay $500 or more for Apple's iPhones.
That bet paid off. Windows is now a dwindling fraction of Microsoft's business. While the company still runs consumer-focused businesses such as Bing search and Xbox gaming, it has prioritised business-oriented services such as its Office line of email and other workplace software, as well as newer additions such as LinkedIn and Skype. But its biggest growth has happened in the cloud, particularly the cloud platform it calls Azure. Cloud computing now accounts for more than a quarter of Microsoft's revenue, and Microsoft rivals Amazon as a leading provider of such services.
Wedbush analyst Dan Ives said Azure is still in its early days, meaning there's plenty of room for growth, especially considering the company's large customer base for Office and other products.
"While the tech carnage seen over the last month has been brutal, shares of (Microsoft) continue to hold up like the Rock of Gibraltar," he said.
Being less reliant on consumer demand helped shield Microsoft from holiday season turbulence and US-China trade war jitters affecting Apple and other tech companies.
President Donald Trump amplified those tariff concerns when he told The Wall Street Journal in a story published late Monday that new tariffs could affect iPhones and laptops imported from China.
The iPhone maker had already seen its stock fall after reporting a mixed bag of quarterly results in early November amid fears about how the technology industry will fare in the face of such threats as rising interest rates, increased government regulation and Trump's escalating trade war with China.
Apple also spooked investors with an unexpected decision to stop disclosing how many iPhones it sells each quarter. That move has been widely interpreted as a sign that Apple foresees further declines in iPhone sales and is trying to mask that.
While smartphones caused the downturn in personal computers years ago, sales of smartphones themselves have now stalled. That's partly because with fewer innovations from previous models, more people choose to hold on to the devices for longer periods before upgrading.
Daniel Morgan, senior portfolio manager for Synovus Trust, said Microsoft is outperforming its tech rivals in part because of what it's not. It doesn't face as much regulatory scrutiny as advertising-hungry Google and Facebook, which have attracted controversy over their data-harvesting practices. Unlike Netflix, it's not on a hunt for a diminishing number of international subscribers. And while Amazon also has a strong cloud business, it's still more dependent on online retail.