Microsoft chief executive Steve Ballmer has announced he will retire within 12 months, opening a new chapter for a company struggling to keep pace with the fast-changing technology sector.

Microsoft shares leapt as much as nine percent in pre-market trade and closed up 7.3 percent at $34.76, after the surprise announcement sparked a rally in the stock.

"There is never a perfect time for this type of transition, but now is the right time," Ballmer said in a statement on Friday.

There is never a perfect time for this type of transition, but now is the right time

Steve Ballmer, Microsoft CEO

"My original thoughts on timing would have had my retirement happen in the middle of our company's transformation to a devices and services company. We need a CEO who will be here longer term for this new direction."

Ballmer took over as CEO in 2000 from co-founder Bill Gates, a classmate and friend from their days at Harvard University in the 1970s.

When Ballmer took over, Microsoft was the undisputed technology sector leader, and the world's largest company in market value.

But in recent years it has struggled as consumers began to move from desktop and laptop PCs to mobile devices.

While its Windows software is used on the vast majority of personal computers, Microsoft has had little impact in the fast-growing segments of tablets and smartphones.

Ballmer, 57, will continue in the interim as CEO "and will lead Microsoft through the next steps of its transformation to a devices and services company," a company statement said.

The board of directors has appointed a special committee to direct the process chaired by independent director John Thompson and including Gates, Chuck Noski and Steve Luczo.

Microsoft said it is working with Heidrick & Struggles International, an executive recruiting firm, and will consider both external and internal candidates.

Source: Agencies