Uber is handing over its China operations to Didi in an acquisition deal that would end the battle between the two ride-hailing companies to dominate the market.

Uber Technologies Inc. is selling its China operations to fierce rival Didi Chuxing, in a market that’s cost Uber $2 billion over the past two years in a price war for the growing market. Didi will invest $1 billion in Uber’s global company, people familiar with the matter said.

The huge losses in China have been one of the main sticking points holding up Uber’s potential initial public offering, according to people familiar with the matter. Uber has been profitable in the U.S. and Canada, and can now turn its attention to other markets where it’s been fighting for market leadership. Competitors for ride-haling and ridesharing services have included Grab in Southeast Asia, Ola in India, and Lyft in the U.S.

“The biggest existential threat to Uber over the last two months was that in China they were losing capital in a way that potentially threatened the rest of their worldwide operations,” said Arun Sundararajan, a New York University professor. “The fact is that in the short term it may seen as a loss, but in the long run it’s a good move. Now they can focus on the rest of the world.”

Uber Technologies and Uber China’s other shareholders, including search giant Baidu Inc., will receive a 20 percent economic stake in the combined company. Didi founder Cheng Wei and Uber Chief Executive Officer Travis Kalanick will join each other’s boards, according to Bloomberg.

SEE ALSO: Apple Investing $1B in Chinese Ridesharing Giant Didi

Last year, China’s ride-hailing leaders Didi and Kuaidi joined forces to fight off Uber. The merged company Didi Chuxing brought together backers Alibaba Group Holding Ltd. and Tencent Holdings Ltd., the country’s most valuable internet businesses. Apple Inc. joined in this year with a $1 billion investment in Didi.

The Didi-Uber deal is subject to government approval. The Chinese government has been supportive of ride-hailing services, last week passing a new rule legalizing them and paving the way for further expansion of these businesses.

The purchase of Uber’s China business may complicate Didi’s alliance with other ride-hailing companies. Didi had agreed to work with Lyft, Ola, and Grab to create a global force to take on Uber.