Microsoft’s quarterly profit jumped an unexpected 17 percent largely because of its Office software and services offered to companies, a business line that is buoying the firm’s fortunes as it faces a fast-shrinking personal computer market.

The Redmond, Wash., company said net income rose to $5.24 billion as revenue climbed 16 percent, to $18.5 billion, for the three months that ended Sept. 30. The results, which were well above analysts’ expectations, drove up the stock by as much as 6 percent in after-hours trading Thursday.

The results highlighted the growing importance of Office and business services for Microsoft. Following in the footsteps of other big tech companies whose fortunes were once tied to the PC, Microsoft — the world’s largest software company — has said it plans to reinvent itself as a “devices and services” company.

But of the two sides of the company — one that sells products to consumers and the other to businesses — the latter holds the most promise, analysts say. Microsoft said revenue from its consumer line, including PCs, the Xbox video-game console and the Surface tablet, grew 4 percent, as sales from the commercial business gained 10 percent.

The business of selling software and services to companies, however profitable, is becoming crowded. Both Google and Apple have been making headway in getting gadgets and software in the hands of workers.

Google already offers free word-processing and spreadsheet programs online. And on Wednesday, Apple took a swing at the crown jewel of Microsoft’s offerings, announcing it would give away its Office competitor called iWork — which includes a word processor, a spreadsheet program and presentation software — free to consumers who buy a new tablet or Mac. As they unveiled the latest iPad, Apple executives also made not-too-subtle-jabs at Microsoft’s tablet and computer strategy.

Critics of Microsoft piled on, questioning why the company has been slow to bring its Office software to the iPad, which dominates the tablet market.

In a feisty response, Microsoft’s corporate vice president of communication Frank Shaw took an unusually public swing at its longtime rival.

Apple’s decision, Shaw wrote on Microsoft’s official blog, was “not a very big (or very good) deal.”

“When I see Apple drop the price of their struggling, lightweight productivity apps, I don’t see a shot across our bow,” he said. “I see an attempt to play catch up.”

Microsoft on Wednesday said little about the search for a new chief executive to replace Steve Ballmer, who announced in August that he would step down within 12 months after 13 years at the company.

“Microsoft, for the first time in its history, is battling from a position of being the underdog,” Gartner analyst David Cearley said. “There’s a cloud of uncertainty when it can’t afford uncertainty. It has to be moving.”

Follow The Post’s new tech blog, The Switch, where technology and policy connect.