BEIJING — 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, Bloomberg reported Monday, creating a $35 billion dollar company.

Didi will also invest $1 billion in Uber, which will continue to operate as a separate brand, according to multiple reports.

The news, if confirmed, will be welcomed by investors who’ve 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 dollars 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 headlines around the world after receiving a $1 billion dollar 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 November 1st.

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.