Nokia, which will continue as a maker of networking equipment and holder of patents, was once the world's dominant handset manufacturer but was long since overtaken by Apple and Samsung in the highly competitive market for more powerful smartphones.
Nokia's Canadian boss Stephen Elop, who ran Microsoft's business software division before jumping to Nokia in 2010, will now return to the US firm as head of its mobile devices business.
He is being discussed as a possible replacement for Microsoft's retiring CEO Steve Ballmer, who is trying to remake the US firm into a gadget and services company like Apple before he departs, after disastrous attempts so far to compete in mobile devices.
In three years under Elop, Nokia saw its market share collapse and its share price shrivel as investors bet heavily that his strategy would fail.
In 2011, after writing a memo that said Nokia was falling behind and lacked the in-house technology to catch up, Elop made the controversial decision to use his former firm Microsoft's Windows Phone for smartphones, rather than Nokia's own software or Google's ubiquitous Android operating system.
Nokia, which had a 40 percent share of the handset market in 2007, now has a mere 15 percent market share, with an even smaller 3 percent share in smartphones.
The sale of the handset business is not the first dramatic turn in the 148-year history of a company which has sold everything from television sets to rubber boots. But it was felt as a hard blow in its native Finland, even among hard-nosed investors who saw the sale as a final chance to salvage value.
"I have mixed feelings, because I'm a Finn. As a Finnish person, I cannot like this deal. It ends one chapter in this Nokia story," said Juha Varis, Danske Capital's senior portfolio manager whose fund owns Nokia shares. "On the other hand, it was maybe the last opportunity to sell it."
Varis was one of many investors critical of Elop's decision to bet Nokia's future in smartphones on Microsoft's Windows phone software, which was praised by tech reviewers but never caught on with consumers.
"So this is the outcome: the whole business for 5 billion euros. That's peanuts compared to its history," he said.
Finns lamented the decline of their former champion. Alexander Stubb, Finland's minister for European Affairs and Foreign Trade, said on his Twitter account: "For a lot of us Finns, including myself, Nokia phones are part of what we grew up with. Many first reactions to the deal will be emotional."
It is also a pivotal moment for Microsoft, which still has huge revenues from its Windows computer operating system, Office suite of business software and the X-Box game console, but never managed to set up a profitable mobile device business.
Microsoft's own mobile gadget, the Surface tablet, has sold tepidly since it was launched last year.
"It's a bold step into the future - a win-win for employees, shareholders and consumers of both companies," Ballmer said in a statement. "Bringing these great teams together will accelerate Microsoft's share and profits in phones and strengthen the overall opportunities for both Microsoft and our partners across our entire family of devices and services."
The move leaves the Finnish company with Nokia Solutions and Networks, which competes with the likes of Ericson and Huawei in telecoms equipment, as well as a navigation business and a broad portfolio of patents, which will be licensed to Microsoft.
Finnish media pounced on Elop, who laid off thousands of the country's workers while the company's market share shrivelled.
For many Finns, the notion that a former Microsoft executive had come to Nokia, bet the firm's future on alliance with Microsoft and then delivered it into Microsoft's hands, was a particularly galling snub to national pride.
"Jorma Ollila brought a Trojan horse to Nokia," widely-read tabloid Ilta-Sanoma declared in a column, referring to Elop's predecessor, who built Nokia into a global powerhouse but was blamed for being late to recognise the threat of Apple's iPhone and the smartphone revolution.
The Nokia deal thrusts Microsoft deeper into the hotly contested mobile phone market, despite some investors urging it stick to its core strengths of business software and services.
Elop will return as Microsoft's board ponders a successor to Ballmer, who will depart sometime in the next 12 months.
Activist fund manager ValueAct Capital Management, which has been offered a board seat, is among those concerned with Ballmer's leadership and his attempts to plough headlong into the lower-margin, highly competitive mobile devices arena.
Others applauded Ballmer's aggressive gambit.
"Microsoft cannot walk away from smartphones and the hope that other vendors will support Windows Phone is fading fast. So buying Nokia comes at the right time," said Carolina Milanesi, an analyst at Gartner.
"In today's market it is clear that a vertical integration is the way forward for a company to succeed. How else could Microsoft achieve this"
As part of Microsoft, Elop will head an expanded Devices unit. Julie Larson-Green, who in July was promoted to head a new Devices and Studios business in Ballmer's reorganisation, will report to Elop when the deal is closed.
The sale price of Nokia's phone business, at about one-quarter of its sales last year, represented a "fire sale level," according to analyst Tero Kuittinen at consultancy Alekstra, although others disagreed on pricing.
"What should be paid for declining business, where market share has been constantly lost and profitability has been poor" said Hannu Rauhala, an analyst at Pohjola Bank. "It is difficult to say if its cheap or expensive."
Nokia is still the world's No. 2 mobile phone maker behind Samsung, but it is not in the top five in the more lucrative and faster-growing smartphone market.
Sales of Nokia's Lumia series have helped the market share of Windows Phones in the global smartphone market climb to 3.3 percent, according to consultancy Gartner, overtaking ailing BlackBerry Ltd for the first time this year. Still, Google Inc's Android and Apple's iOS system make up 90 percent of the market.
Nokia said in a statement it expected that, apart from Elop, senior executives Jo Harlow, Juha Putkiranta, Timo Toikkanen, and Chris Weber would transfer to Microsoft when the deal is concluded. It did not say what roles they would take there.
Nokia board chairman Risto Siilasmaa would take over CEO duties while the Finnish firm looked for a new CEO, it said.
The deal is expected to close in the first quarter of 2014, subject to approval by Nokia shareholders and regulators.
The changing fortunes of Finland's Nokia
Here is a look at Nokia's changing face after it agreed to sell its phone business and license for its patents for 5.44 billion euros ($7.2 billion) to Microsoft.
* Named in 1871 after the Nokianvirta river where mining engineer Fredrik Idestam set up his second paper mill, Nokia spent more than a century making tyres, boots or cables before producing the first handheld mobile phone, the Mobira Cityman, in 1987.
* Nicknamed the "Gorba" after former Soviet leader Mikhail Gorbachev was pictured using one, it weighed a thumping 800 grams and carried an even more daunting price tag - 24,000 Finnish marks (4,650 euros).
* In 1992, Nokia sold off its non-mobile divisions and launched its first digital handheld GSM phone, the Nokia 1011.
* The basic Nokia 1100, launched in 2003, was a runaway hit, shifting 250 million units, making it not just the world's best-selling mobile, but the most popular consumer electronics device of any kind.
* Nokia remained the world's largest vendor of mobile phones until knocked off the top spot by Samsung in 2012, but it lost its lead in the lucrative smartphone market a year earlier, having been on the back foot since the launch of Apple's iPhone in 2007.
* Nokia unveiled its first Windows Phone handsets, the Lumia 710 and 800, in October 2011 after a strategic decision by new Chief executive Stephen Elop to ditch its own ailing Symbian operating system in favour of the Microsoft equivalent.
* Nokia picked up the pace of product launches in 2013, including the unveiling of its Lumia 1020 with a 41-megapixel camera. Also this year, it announced a 15-euro phone, its cheapest phone ever.
* Although Nokia also said in July it had shipped 7.4 million Lumia smartphones in the quarter, up 32 percent from Q1, it was fewer than the 8.1 million units analysts had anticipated. Nokia now boasts only around 15 percent of the handset market share, with an even smaller 3 percent share in smartphones.