Shares rallied as much as 3.5 percent to a high of $145.67 apiece before paring their gains.
"This contract will address critical and urgent unmet warfighter requirements for modern cloud infrastructure at all three classification levels delivered out to the tactical edge," the Pentagon said in a press release.
The Department of Defense says the Joint Enterprise Defense Infrastructure system contract, or JEDI, will help the U.S. government store and process classified data, allowing the armed forces to use artificial intelligence to enhance its planning and fighting capabilities. The contract has a base period of two years and a $1 million guarantee.
Microsoft winning the contract was a surprise to many as Amazon was believed to be the front runner. Oracle and IBM were also vying for the contract, but were earlier eliminated from the process. Oracle filed a lawsuit in December, calling the process unfair and illegal.
Last week, Microsoft announced first-quarter results that topped Wall Street estimates. The company said revenue from its cloud-computing business soared 36 percent year-over-year to a record $11.6 billion.
Shares have gained more than 38 percent this year. Microsoft is the second-largest publicly traded U.S. company, commanding a market capitalization of $1.099 trillion which trails only Apple ($1.12 trillion).