(Bloomberg) -- Donald Trump and Kim Jong Un will meet next month to negotiate a deal that could avert nuclear war. But the ultimate success of any agreement hinges on someone else: China’s President Xi Jinping.

As North Korea’s largest trading partner, China’s enforcement of United Nations sanctions helped bring Kim to the negotiating table while also shielding his regime from Trump’s warnings of “fire and fury.” Now that Trump and Kim are meeting, Xi can support any deal that is good for China and undermine anything that goes against its interests.

China already appears to be using that leverage in discussions on trade. Last week, Trump said Xi “could be influencing” Kim to take a harder line with the U.S. after North Korea threatened to walk away from the summit. The U.S. and China on Saturday declared a truce in their ongoing trade spat, paving the way for a greater focus on North Korea.

“China must continue to be strong & tight on the Border of North Korea until a deal is made,” Trump said on Twitter on Monday. “The word is that recently the Border has become much more porous and more has been filtering in. I want this to happen, and North Korea to be VERY successful, but only after signing!”

China faces a difficult balancing act. It has repeatedly called for talks between the U.S. and North Korea to avoid a war or regime collapse, which could devastate its economy and lead to a refugee crisis or potentially U.S. troops on its border. On the other hand, China wants to avoid drawing North Korea closer to the U.S. and South Korea, exacerbating its own security concerns.

China ‘Indispensable’

Ahead of the unprecedented summit, Xi has inserted himself into the discussion. Kim has visited China twice in recent months to meet with Xi, while Trump has also spoken by phone with the Chinese leader.

"Even if the U.S. and South Korea try to weaken China’s impact in the negotiation process, Xi and Kim’s recent two meetings have proved that China and its support are indispensable," said Yue Li, senior fellow at the Pangoal Institution, a Beijing-based think tank. "Even though it won’t sit at the negotiating table in Singapore, China plays a role as a stabilizer in this region."

China possesses a unique combination of carrots and sticks that could help a deal succeed or cause it to unravel. The country’s economic leverage over the North -- China supplied 85 percent of North Korea’s $3.47 billion in imports in 2015 -- means it will be critical to any economic inducements offered as part of the deal.

Sanctions Hope

Already China has appeared to give Kim hope of easing sanctions against his regime that curb fuel imports and ban exports of everything from seafood to coal. On a trip to Beijing in March -- Kim’s first outside the country since taking power in 2011 -- Xi told him that China has made a “strategic choice” to have friendly ties with North Korea, and they would “remain unchanged under any circumstances.”

“If relations with the U.S. deteriorate or China’s not happy with the U.S. approach to negotiations, there are many ways it could quietly ease up on implementation and enforcement without formally violating the sanctions,” said Michael Kovrig, senior adviser for Northeast Asia at the International Crisis Group and a former Canadian diplomat stationed in Beijing.

‘Guarantor’

Internationally, there are high hopes that China will play a positive role.

“China can be a guarantor to North Korea that if they give up their nuclear capacity, the United States will not be in a position to harm them,” United Nations Secretary-General Antonio Guterres told Bloomberg in an interview last week. “And for the United States, China can also be a guarantor that if there is an agreement, that the agreement is effectively implemented by the North Koreans.”

Still, any efforts at mediation are hindered by China’s complex and at times difficult ties with both the U.S. and North Korea. While China sided with Pyongyang in the Korean War and has a mutual defense treaty, it’s unclear how Beijing would act in a conflict -- particularly if North Korea kicked things off.

China also has to contend with the longstanding tendency of both the U.S. and North Korea to walk away from negotiations, not to mention the volatile personalities of Trump and Kim.

“It can’t ensure compliance from either side,” Kovrig said. “It has leverage and influence over North Korea, but ultimately can’t force it to implement. Beijing has even less influence over U.S. policy and President Trump.”

China’s Interests

Still, China has a strong interest in shaping any potential deal. In particular, it’s likely to want a reduction in the U.S. troop presence and an increase in trade with North Korea to help revive its ailing northeast economy. Home sales in the Chinese border city of Dandong are already surging on hopes trade between the two countries might increase.

China also shares the goal of denuclearizing the Korean Peninsula. China would suffer from any deal that eliminates North Korea’s long-range missiles capability of hitting America while allowing the U.S. to maintain deterrence against the regime’s nuclear weapons and short-range missiles, according to Zhang Liangui, a former professor at the Chinese Communist Party’s Central Party School.

"In this case, the U.S. and its allies will be free from nuclear attack but North Korea’s surrounding countries like China would be affected," Zhang said. “This scenario isn’t likely, but we need to beware.”

To contact Bloomberg News staff for this story: Peter Martin in Beijing at pmartin138@bloomberg.net;Dandan Li in Beijing at dli395@bloomberg.net

To contact the editors responsible for this story: Daniel Ten Kate at dtenkate@bloomberg.net, Andy Sharp

©2018 Bloomberg L.P.