At last, China’s ride share war may be over.

The victor: Didi Chuxing, China’s biggest ride-hailing service. The vanquished: Uber China, the local arm of the U.S. firm.

In a dramatic end to a brutal, years-long battle, Uber will swap its China business for a 20 percent stake in its erstwhile rival, reportedly creating a $35 billion company.

Didi will also invest $1 billion in Uber, which will continue to operate as an independent service, the Chinese company confirmed in a statement released on Monday.

The news will likely be welcomed by investors who have watched both firms bleed cash in twin bids to gain ground in the massive Chinese market.

It will also mark the end of Uber’s high-profile push into the China.

The company started operating here in 2013 and has expanded aggressively since, with Uber China quickly becoming the firm’s largest market.

As the competition intensified, both companies spent big, subsidizing drivers and rides to keep prices low and customers loyal. 

Travis Kalanick, Uber’s chief executive officer, has said Uber was losing $1 billion a year here, but called his strategy “sustainable.”

Clearly, it was not.

In the end, Uber proved unable to beat out the cash-rich local champion. Didi recently made global headlines after receiving a $1 billion investment from Apple, followed by $7 billion in a subsequent round of fundraising

Didi is backed by China's big tech firms and is partnered by Lyft, an Uber rival. A 2016 report by CNIT Research, a Chinese market-research firm, found that Didi was taking about 85 percent of ride orders, compared to Uber’s less than 8 percent market share. 

In an as-yet-published blog post seen by Bloomberg, Kalanick explained the decision to call a truce. “As an entrepreneur, I’ve learned that being successful is about listening to your head as well as following your heart,” he wrote. 

“Uber and Didi Chuxing are investing billions of dollars in China and both companies have yet to turn a profit there. Getting to profitability is the only way to build a sustainable business that can best serve Chinese riders, drivers and cities over the long term,” he added.

Didi may find its prospects are good. The Chinese government just last week moved to clarify the legal standing of ride sharing, saying it will legalize the billion-dollar industry by Nov. 1. 

Despite the billion-dollar stakes, companies like Uber and Didi were previously operating in a legal gray zone, with drivers in some areas facing penalties, even arrest, and others operating freely.

Gu Jinglu in Beijing contributed to this report.