Microsoft's profit forecast was better than Wall Street's forecast, helped by growth in its cloud computing business, but it took a $13.8 billion one-time charge due to the new US tax law.
Stock of the world's largest software company, which have risen almost 50% over the past 12 months, initially fell in after-hours trading but later moved into positive territory.
The quarter was the 10th in a row of more than 90% revenue growth for its flagship Azure cloud computing service, which directly competes with Amazon.com's Web Services.
Since chief executive Satya Nadella took the helm in 2014, Microsoft's cloud business - which includes products such as Office 365, Dynamic 365 and Azure - has emerged as a major growth area.
Revenue from what Microsoft calls its intelligent cloud segment rose 15.3% to $7.8 billion in the company's fiscal second quarter, including 98% growth for Azure.
Analysts on average had expected $7.51 billion, according to Thomson Reuters.
Amazon Web Services is the leader of the $14.4 billion cloud computing market with more than 31.8% market share.
But Azure has been growing fast and holds the second position with 13.9% of the market, according to 2017 third quarter estimates by research firm Canalys.
Microsoft's tax charge lead to a net loss of $6.30 billion, or 82 cents per share, in the quarter ended December 31, compared to a profit of $6.27 billion, or 80 cents per share, a year earlier.
Excluding one-time items it earned 96 cents per share, beating analysts' average expectation of 86 cents.
Many US companies have taken large one-time charges this quarter to account for changes to the US tax law made in December, which cut the overall corporate rate and offered a lowered rate for companies repatriating overseas profits to the US.
Besides Azure, Microsoft’s other businesses also grew.
Revenue from its productivity and business unit, which includes the Office 365 service, was up 24.7% to $8.95 billion.
Revenue at Microsoft’s "more personal computing" unit, which includes Windows, Xbox and Surface, rose 2.36% to $12.17 billion.
The company said its overall revenue climbed 12% to $28.92 billion, beating analysts’ expectations of $28.4 billion.