When Sony Corp. unveiled a cloud gaming pact with archrival Microsoft Corp., it surprised the industry. Perhaps no one was more shocked than employees of Sony’s PlayStation division, who have spent almost two decades fighting the U.S. software giant in the $38 billion video game console market.

Last week, the companies announced a strategic partnership to codevelop game streaming technology and host some of PlayStation’s online services on Microsoft’s Azure cloud platform. It comes after PlayStation spent seven years developing its own cloud gaming offering, with limited success.

Negotiations with Microsoft began last year and were handled directly by Sony’s senior management in Tokyo, largely without the involvement of the PlayStation unit, according to sources familiar with the matter. Staff at the gaming division were caught off guard by the news. Managers had to calm workers and assure them that plans for the company’s next-generation console weren’t affected, according to the sources, who asked not to be identified discussing private matters.

That difficult moment is part of a painful lesson that Sony and many other technology companies are facing as the world’s leading cloud-computing providers become more powerful. If you aren’t spending billions of dollars a year on data centers, servers and network gear, you can’t keep up.

Faster internet speeds are starting to allow games to be played remotely without the need for a local machine. That’s a threat to PlayStation, which generates a third of Sony’s profits. Microsoft’s Xbox faces a similar risk, but the software giant has the second-largest cloud service, so it has a strategic answer. The other leading cloud providers, Google LLC and Amazon.com Inc., are building their own cloud-gaming services.

Realizing that his home-grown cloud service isn’t going to cut it, Sony Chief Executive Officer Kenichiro Yoshida is being forced to collaborate with, rather than confront, his old gaming nemesis.

“Sony feels threatened by this trend and the mighty Google, and has decided to leave its network infrastructure buildup to Microsoft,” said Asymmetric Advisors strategist Amir Anvarzadeh. “Why would they sleep with the enemy unless they feel threatened?”

Sony jumped 9.9 percent Friday, the most in 18 months. The company also announced a record share buyback, but analysts pointed to Yoshida’s speed in responding to a shifting video game industry as a positive factor.

This shows “a new Sony” and should be applauded by investors, SMBC Nikko Securities Inc. analyst Ryosuke Katsura wrote in a report. “Management is adapting rapidly to change.’

A Sony spokesman confirmed that talks with Microsoft began last year, but declined to provide further details.

Sony became the first big video game company to enter cloud gaming when it bought U.S. startup Gaikai Inc. in 2012 for $380 million. Three years later, it rolled out PlayStation Now, letting users play games hosted on servers far from their living rooms. The service has since attracted 700,000 paying subscribers, but a decision to host it in-house has led to ongoing complaints about choppy connectivity.

“PlayStation Now has been a very limited service,” said David Cole, founder and chief executive officer of DFC Intelligence Inc.

The company’s other online game service and main cash cow, PlayStation Network, enables multiplayer matches of games running on PlayStation 4 consoles. For now that is still hosted by the other giant of cloud computing: Amazon Web Services. Sony and Amazon held talks last year for a deeper collaboration on cloud gaming but couldn’t agree on commercial terms, according to a person familiar with the matter. That led to Sony’s discussions with Microsoft, the person said. Amazon is currently developing its own cloud gaming service, it was reported last year.

The pivot toward Microsoft was preceded by several key personnel changes at Sony, including moving some senior PlayStation Now staff to other divisions, the person said. PlayStation boss John Kodera, who rose through the ranks running the network side, was also replaced in February, a little more than a year after taking the top job.

The key question is who really wins from the partnership. Most analysts agree that, at least in the short to medium term, it’s a positive for Sony. Cloud gaming isn’t ready for prime time yet. When Google unveiled Stadia in March, some users reported mixed results, including delays in registering actions and reduced graphics quality.

Cloud gaming will account for just 2 percent of the industry’s revenue by 2023, according to IHS Markit. That’s why Sony and Microsoft are moving ahead with their next-generation consoles, expected next year. Securing access to Azure gives Yoshida a powerful hedge against a future scenario where cloud gaming does end up making consoles obsolete.

Microsoft may come out an even bigger winner. The Xbox unit continues to churn out games and consoles but is now increasing focus on ways to sell more cloud software. In March, it announced a lineup of services for game development and cloud hosting that it’s hawking to game companies of all sizes. Landing console king Sony makes it more likely that Azure, and not Amazon or Google, becomes the industry standard for cloud deployment.

“Microsoft is the clear winner that Sony picked their technology even though they are a direct competitor in the gaming space,” said DFC’s Cole.

Over the long term, some are warning Sony could be the loser. Currently it charges publishers like Electronic Arts Inc. and Capcom Co. up to 30 percent of sales made through PlayStation consoles. But if streaming takes off, it will have to compete against Microsoft while paying its rival for cloud access. That could leave Sony struggling to stand out both in technical and pricing terms.

“This move raises some serious questions about its future dominance,” said Anvarzadeh of Asymmetric Advisors.

It’s also unclear how antitrust regulators will respond to two of the three players in the console market teaming up to develop a key technology, especially as it involves the world’s largest company by market value. Cooperation by the No. 1 and No. 2 in any industry — say AT&T Inc. and Verizon Communications Inc. — to the deterrence of rivals would likely prompt pushback.

Regardless of when and if cloud gaming takes off, securing exclusive titles will continue to be critical for Sony, according to Piers Harding-Rolls, IHS Markit’s head of games research.

Similar to how Netflix Inc. fights Prime Video while relying on Amazon for cloud hosting, and how Apple Inc. competes against Samsung Electronics Co. while buying its components, Sony’s core strategy of accumulating a strong lineup of games remains unchanged.

“Exclusive content remains key,” said Harding-Rolls.