Just a few years ago, Microsoft was seen as a lumbering has-been of the technology world.

It was big and still quite profitable, but the company had lost its luster, failing or trailing in the markets of the future like mobile, search, online advertising and cloud computing. Its stock price languished, inching up 3 percent in the decade through the end of 2012.

It’s a very different story today. Microsoft is running neck and neck with Apple for the title of the world’s most valuable company, both worth more than $850 billion, thanks to a stock price that has climbed 30 percent over the last 12 months.

So what happened?

The company built on its strengths

There is a short-term explanation for Microsoft’s market rise, and there is a longer-term one.

The near-term, stock-trading answer is that Microsoft has held up better than others during the recent sell-off of tech company shares. Apple investors are worried about a slowdown in iPhone sales. Facebook and Google face persistent attacks on their role in distributing false news and conspiracy theories, and investor concerns that their privacy policies could scare off users and advertisers.