Microsoft has agreed to pay €5.44 billion ($7.9 billion) for Nokia's devices business and licence patents as the Finnish company, once the biggest maker of mobile phones, struggles to maintain market share.
The deal includes paying €3.79 billion ($5.6 billion) for the devices unit and €1.65 billion ($2.4 billion) for patents, the companies said in a statement on Tuesday.
Nokia chief executive Stephen Elop will step aside to return to Microsoft, they said.
Nokia is coping with cash-flow challenges stemming from weaker demand as its phones lose share to devices from Apple and handsets using Google's Android operating system.
Elop has cut more than 20,000 jobs and suspended the company's dividend in January in an attempt to improve its finances.
"After a thorough assessment of how to maximise shareholder value, including consideration of a variety of alternatives, we believe this transaction is the best path forward for Nokia and its shareholders," chairman Risto Siilasmaa said.
Siilasmaa will become interim CEO of Nokia.
Nokia reported in July a 27 per cent drop in the number of handsets sold in the second quarter. It's lost more than €5 billion ($7.3 billion) in nine quarters.
Microsoft has battled to stay relevant as consumers have shifted from using its core Windows software for PCs toward mobile devices from Apple and others.
Facebook and Google have also pushed ahead in social networking and online advertising, areas where Microsoft remains weak.