The Pentagon awarded Microsoft Corp. a hotly contested and controversial contract to build a large cloud-computing system for the U.S. military in a major setback to rival Amazon.com Inc., which was widely seen as the front-runner.

The so-called JEDI contract could be worth up to $10 billion to Microsoft over a 10-year period if the Pentagon exercises all options under the deal, the Defense Department said late Friday.

Amazon...