Uber Technologies Inc.'s costly battle for ride-hailing supremacy in China has finally come to an end, after a deal was made with local rival Didi Chuxing Technology Co. The American company will swap its local operations there for a minority stake in their Chinese counterpart. Didi has confirmed that Uber and its UberChina investors will take a 20% stake in the company. Combined with Uber's China business - valued at $8 billion - Didi now has a total valuation of nearly $36 billion.

The news comes as further confirmation of the difficulty American companies have had trying to establish a foothold in China. Uber was once a rare exception, as a U.S. tech firm making inroads in the Chinese market in 2013. Much of its early success stemmed from the company's foresight to create local teams based around different cities, which allowed for flexibility and quick responses to moves from competition. In addition, Chief Executive Travis Kalanick met with officials in China's Communist Party frequently, helping the company avoid regulatory tripwires that other American companies have stumbled on. But gaining entry was not enough, as Uber also had to learn how to lure customers and harm competitors in the Chinese market. In addition, engineers had to deal with drivers that faked rides to gain commission, and marketers had to make up for being blocked from advertising on China's biggest social network, WeChat, because the internet giant Tencent was an early investor in Didi. All this, coupled with the fact that Didi had advantage in scale, homecourt, and the backing of China's tech giants, made competing extremely difficult.

As a result, Uber now joins the ranks of peers like eBay (EBAY  ) and Google (GOOGL  ), with the former being outmaneuvered by Alibaba and the latter leaving China after being targeted by government-sponsored cyberattacks. Other than Apple Inc. (AAPL  ), which has also seen slowing sales as of late, few other American companies have managed to go toe-to-toe with Chinese rivals for local consumers.

Ultimately, however, there is financial upside for Uber in this outcome. The company's $2 billion investment in the Chinese market will result in a $7 billion share of a growing Didi Chuxing. It will also receive a $1 billion investment from Didi in its operations in the rest of the world, called Uber Global. Not to mention, Uber will save all the cash it would have spent competing in China, for other projects. Kalanick has asserted that the merger will free up resources for "bold initiatives focused on the future of cities-from self-driving technology to the future of food and logistics." After Uber and Didi Chuxing have both invested billions of dollars in China without turning any profit, Kalanick has seemingly come to terms with the fact that operating in China is "only possible with profitability." And now that their costly battle to win China is finally over, Uber looks ready to move on to their next audacious goal.