Alibaba Group Holding Ltd. bought NetEase Inc.’s Kaola e-commerce platform for about $2 billion and invested in its music streaming service, forging a rare partnership between two of China’s largest internet giants.

The deal hands Alibaba the biggest Chinese online marketplace for foreign brands after its own Tmall Import and Export. Kaola will now operate independently but under new Chief Executive Officer Alvin Liu, a Tmall veteran. Separately, Alibaba and billionaire co-founder Jack Ma’s Yunfeng Capital will invest $700 million in NetEase Cloud Music. NetEase remains the controlling shareholder of its music app.

Alibaba and NetEase -- both based in the prosperous eastern city of Hangzhou -- have long fought social media titan Tencent Holdings Ltd. across several fronts but the landscape is shifting. The emergence of Tencent-backed rivals like Pinduoduo Inc. is testing Alibaba’s dominance of retail. NetEase has long been a distant runner-up to Tencent in gaming and now also music streaming, while Alibaba has its own music app Xiami. The sale of the low-margin Kaola platform now allows NetEase to focus on its bread-and-butter gaming business.

“NetEase can further optimize its costs while Alibaba strengthens its leadership in cross-border e-commerce,” Thomas Chong and Ken Chong, analysts at Jefferies, wrote Friday. “On the other hand, we believe NetEase Cloud Music can benefit from potential synergies with the Alibaba ecosystem.”

The Kaola deal creates a dominant bazaar for consumers seeking foreign labels and goods. Alibaba and Kaola, which is loss-making on an operational level, controlled almost 60% of all transactions on China-based platforms for foreign brands in the second quarter, according to research firm Analysys.

It also deepens a seeming alliance. NetEase founder William Ding and Alibaba CEO Daniel Zhang exchanged good-natured banter during a long TV interview aired in China just last month. Asked about their rivalry, Ding joked: “Many of our employees might be husbands and wives.”

NetEase Music most recently raised $600 million in November when Baidu Inc., General Atlantic and Boyu Capital participated in a fundraising round. The latest capital injection comes after China’s antitrust authority launched a probe into its much larger rival, Tencent Music Entertainment Group, over its licensing practices. Under government pressure, Tencent Music and NetEase Music last year agreed to relicense more than 99% of their music catalogs to each other.

“What really matters is the 1% exclusive content,” said Shawn Yang, a Shenzhen-based analyst with Blue Lotus. “Now that NetEase has new funding that can be used to buy copyrights, it will definitely be a threat to TME.”