Microsoft has emerged victorious in a dramatic competition for public cloud resources for the U.S. Defense Department, beating out market leader Amazon Web Services, the Pentagon said on Friday. The contract could be worth as much as $10 billion over a decade, according to a statement.

Microsoft stock rose as much as 3% in extended trading after the announcement, and Amazon stock dipped less than 1%.

The achievement highlights the emergence of Microsoft's Azure cloud as a challenger to AWS and represents the latest victory for Satya Nadella, who took over from Steve Ballmer as Microsoft chief in 2014. Microsoft has also won major cloud-infrastructure deals from companies like Walmart even as AWS has kept growing.

"For over 40 years, Microsoft has delivered innovative, proven and secure technologies to the US Department of Defense. We brought our best efforts to the rigorous JEDI evaluation process and appreciate that DoD has chosen Microsoft," a Microsoft spokesperson told CNBC in an email on Saturday. "We are proud that we are an integral partner in DoD's overall mission cloud strategy. As was articulated throughout the JEDI procurement, the DoD has a singular objective -- to deploy the most innovative and secure commercially available technology to satisfy the urgent and critical needs of today's warfighters."

If the Joint Enterprise Defense Infrastructure deal, known by the acronym JEDI, ends up being worth $10 billion, it would likely be a bigger deal to Microsoft than it would have been to Amazon. Microsoft does not disclose Azure revenue in dollar figures but it's widely believed to have a smaller share of the market than Amazon, which received $9 billion in revenue from AWS in the third quarter.

Early in the process Amazon was seen as the favorite, partly because its AWS business won a deal with the CIA in 2013. Also Amazon had been certified at the highest existing security clearance level, while Microsoft sought to catch up.

Other, smaller cloud rivals like IBM and Oracle were kicked out earlier in the process, which has been contentious and delayed.

In July, President Trump said he was looking at the contract after companies had protested the bidding process.

While Trump didn't cite Amazon CEO Jeff Bezos by name at the time, the billionaire executive has been a constant source of frustration for the president. Bezos owns The Washington Post, which Trump regularly criticizes for its coverage of his administration. Trump also has gone after Amazon repeatedly on other fronts, such as claiming it does not pay its fair share of taxes and rips off the U.S. Post Office.

In August, Defense Secretary Mark Esper said that he would look at it. Then, earlier this week, the Pentagon said that Esper had removed himself from the process because his son Luke Esper works at IBM.

Wedbush analyst Dan Ives called the deal a "game changer" for Microsoft, writing in a note to clients that the deal "will have a ripple effect for the company's cloud business for years to come." He also said that he expects Amazon to challenge the outcome in court, but for Microsoft to prevail.

Nadella once ran the Azure business, among other responsibilities in his 27-year career at Microsoft. He has made cloud a bigger piece of Microsoft while decreasing the emphasis on Windows. The company has also embraced Linux, and after Nadella joined, the cloud was renamed from Windows Azure to Microsoft Azure, reflecting that it's possible to run Linux in Microsoft's public cloud.

"We're surprised about this conclusion," an AWS spokesperson told CNBC in an email. "AWS is the clear leader in cloud computing, and a detailed assessment purely on the comparative offerings clearly lead to a different conclusion. We remain deeply committed to continuing to innovate for the new digital battlefield where security, efficiency, resiliency, and scalability of resources can be the difference between success and failure."