Microsoft reported substantial growth in its cloud computing unit, which helped to boost quarterly profits.
The software giant posted a $3.1bn (£2.4bn) profit for the three months to June.
That was far better than the $3.2bn loss for the same period last year when Microsoft booked hefty charges on writing down the value of mobile phone assets it bought from Nokia.
Shares rose 4% in after-hours trading in New York.
Investors had not been expecting significant company-wide profit growth, but were looking for gains from the cloud computing division called Azure.
Revenue for the unit rose 7% to $6.7bn, while overall adjusted revenue rose $420m to $22.6bn.
Chief executive Satya Nadella has focused on the building Microsoft's expertise in cloud-based services amid slowing PC sales.
"The Microsoft Cloud is seeing significant customer momentum and we're well positioned to reach new opportunities," he said.
Microsoft has been competing with Amazon, Google and others for control in the cloud service and storage space.
Services over hardware
Mr Nadella was behind its biggest takeover last month when it acquire LinkedIn for $26.2bn. Investors want to know Microsoft's plans for the networking site.
The purchase will give Microsoft access to the details of 433 million LinkedIn users, which Microsoft could combine with its Office 365 cloud service to offer its business clients more insight into their customers.
Microsoft's hardware business continued to take a hit during the quarter.
Revenue from the devices unit fell 35%, driven most by a 70% fall in mobile sales.
Microsoft took a $7bn hit last year when it wrote down the value of its Nokia mobile phone division, which it bought in 2014.
Earlier this month Microsoft said it would miss its deadline to get Windows 10 on to one billion mobile devices by next year. It blamed cuts to that division for the delay.
The tablet and hybrid laptop business managed to grow by 9%.