The tech giant said it would benefit all 161,000 of the health service's staff who would also gain access to Office 365.
Hospital boards across the country are currently struggling to keep up with the 12-week treatment time guarantee introduced by the SNP government in 2012.
GPs, consultants and support workers will be able to communicate on the new digital platform, allowing them to share patient information more easily.
Jeane Freeman, Scotland's health secretary, said: "In Scotland, we are building a properly joined-up health and social care system, which is much more focused on getting the right information to the right people at the right time, whether it's a care professional or an individual managing their own health.
"By consolidating hundreds of separate systems across Scotland's NHS and care services, we can ensure that our hard-working staff are able to focus more on patients than processes.
"At the same time, we have a duty to protect people's information safely and securely. As part of that, moving to Office 365 is going to make our systems more resilient."
The two organisations will collaborate for at least three years, with an option to extend for a further two years and will cost up to £80m.
NHS Scotland will also move its computer systems to Windows 10 E5, which contains security features such as "advanced threat protection" Microsoft said. Its behaviour sensors, security analysis in the cloud and threat intelligence will allow staff to respond to cyber-attacks in near-real-time.
First Minister Nicola Sturgeon has been under increased pressure to improve waiting times in Scotland, after numbers for April to June this year showed that just under three quarters (74.6 per cent) of patients were meeting the 12-week treatment guarantee, which she oversaw as health secretary back in 2012.
"The law states that patients will be guaranteed NHS treatment within 12 weeks," Scottish Liberal Democrat leader Willie Rennie said during First Minister's Questions last week.
"It was an SNP flagship law that helped them take power in 2007. And it is a law that the SNP Government has broken over 100,000 times.
"But on Tuesday the Government said they would keep on breaking the law for another three years."
Sturgeon conceded, saying: "The 12-week treatment guarantee, yes it has not been adhered to more than 100,000 times, but 1.6 million patients have been treated within that, patients that might have waited over 12 weeks without that guarantee.
"There are now fewer people waiting more than 12 weeks for treatment than was the case when this government came to office."
Speaking about the deal, Microsoft UK chief executive Cindy Rose said: "NHS Scotland staff do incredible work each and every day, however cross-department collaboration can be challenging due to the use of multiple systems.
"By moving to one common platform in Office 365, staff will have the best tools available to work together seamlessly, ensuring they're able to focus on what counts most - helping patients."