For a couple of weeks in March, after the announcement that Donald Trump had accepted an offer to meet with Kim Jong Un, the outcome of the crisis over North Korea’s nuclear weapons seemed to depend on whether two leaders who had steered their nations toward war could pump the brakes and broker peace. Then, this week, Kim boarded a train to Beijing and scrambled the whole map.

The North Korean leader’s friendly meeting with Chinese President Xi Jinping—his first encounter with another head of state—doesn’t necessarily place Trump in a weaker position heading into nuclear talks with Kim later this spring, said Yun Sun, the director of the China Program at the Stimson Center. But it does make Trump’s position far more complicated. China, which is North Korea’s neighbor, treaty ally, and nearly exclusive trading partner, has reasserted itself as a “central player” in the negotiations.

Just as important, Kim played the United States and China off each other, much like Kim’s grandfather Kim Il Sung exploited doctrinal disputes between China and the Soviet Union to extract economic assistance and security pacts from both of his communist patrons in the early 1960s. Kim’s invitation to Trump stoked Chinese anxiety about being excluded from the summitry (Fear of Missing Out applies as much to international affairs as to human affairs), which will now enable North Korea to take advantage of the “differences, the strategic competition and mistrust between the United States and China,” Yun told me.

“Last week the assumption was that North Korea’s relationship with China was very bad, so going into the [Trump-Kim] summit we could assume that North Korea would be more desperate to have a deal,” Yun said, in reference to the ways in which Kim Jong Un’s weapons tests in defiance of Chinese objections and China’s retaliation with economic sanctions had poisoned ties between the two countries in recent years. Now North Korea has more leverage: “The more options North Korea has, the less isolated North Korea is, the less able the U.S. will be to coerce North Korea in any direction.”

Imagine, for example, that Trump and Kim meet in May and their first conversation—on the shared goal of “denuclearizing” North Korea—goes swimmingly. Then they get to specifics and Kim says he’s happy to dismantle his nuclear program if the United States abandons its “hostile policy” toward his nation. When Trump asks what he means by that, Kim explains that an end to  hostilities could entail a peace treaty concluding the Korean War and the termination of America’s military alliance with South Korea, but would at least have to start with the lifting of some sanctions. Trump says the United States won’t ease an iota of pressure on North Korea until Kim takes significant steps toward completely, verifiably, and irreversibly removing his nuclear weapons. Kim protests: “We haven’t tested a nuclear bomb or ballistic missile in six months! We’re sitting right in front of you at the negotiating table! We deserve a reward.” Trump stays tough: “No way, Little Rocket Man,” he says.

A week ago, Kim might have felt cornered under such circumstances. Now, the Chinese could step into the stalemate and argue that the Kim government has indeed behaved well, that the North Korean people are suffering from sanctions, and that achieving denuclearization requires not just sticks but carrots. The Trump administration, whose new national-security adviser detests diplomatic carrots, might balk at the proposal. But the Chinese could press ahead with economic relief regardless, threatening to blow a China-sized hole in the international sanctions campaign against North Korea. (The North Korea scholar Go Myong Hyun has speculated that one of Kim’s motives for visiting Beijing was to “prepare the ground for the immediate relaxation of sanctions after the U.S.-North Korea talks,” even if that only involves China “turning a blind eye to the smuggling activities along the border.”)

Shen Dingli, a professor of international relations at Fudan University in Shanghai, compared the Chinese and North Korean moves ahead of the Trump-Kim summit to a complex game of cards with the United States. China “wants to use the [North Korea] card to strengthen its position vis-a-vis the U.S., especially in the current ‘trade war,’” and prevent North Korea from falling into the “U.S. orbit,” he told me by email. North Korea “wants to use the China card to strengthen its position vis-a-vis the U.S., especially in the coming negotiation with the U.S. on denuclearization, and play its newly ‘secured’ U.S. card to force China to soften [its] position toward Pyongyang.” (The United States looks poised to play some hands of its own; on Thursday, Trump threatened to delay renegotiation of a trade agreement with South Korea, which has tended to be more accommodating of North Korea than the U.S. has been, until he has finalized a nuclear deal with North Korea. Trade is “a very strong card,” he reasoned.)

Trump could try to avoid getting played by coordinating positions with Xi ahead of his meeting with Kim. The U.S. president might have agreed to talk directly with North Korea’s leader, cutting out China as a middleman, for the same reason Trump prefers bilateral trade deals: The mighty United States is more likely to get what it wants when it goes up against one country rather than multiple countries. But in this case, America could benefit from having the middleman closer to its side. “The only way to constrain the small power’s ability to manipulate big powers is for the big powers to have communications among themselves,” Yun said. “As long as the U.S. and China see each other as a bigger problem, North Korea will be able to manipulate the situation.”

But while China and the United States both oppose nuclear weapons in North Korea, their interests in Korea diverge after that. America fears the capabilities of the Kim regime while China fears the collapse of the Kim regime. What the Chinese government ideally wants from the nuclear talks, Yun said, is for the U.S. and North Korea to sign a peace treaty and for North Korea to give up its nuclear program “step by step” in exchange for the United States withdrawing its troops from the Korean peninsula. According to this vision, “North Korea will remain as a pro-China, friendly, nuclear-free force” while “South Korea will also become pro-China or, at a minimum, neutral between the U.S. and China,” Yun said. The Trump administration, by contrast, has indicated that it ideally wants to maintain its alliance with South Korea even as North Korea fully relinquishes its nuclear weapons.

John Bolton, Trump’s incoming national-security adviser, has gone further, repeatedly suggesting that the United States pursue a diplomatic track of persuading China that it’s in Chinese interests to engineer a “controlled collapse” of the Kim regime by severing its economic lifeline to North Korea, supporting a rival political faction, or more forceful means. As Bolton tells it, China would then permit the absorption of North Korea into South Korea with the understanding that the United States would keep its troops in southern Korea rather than moving them up toward China’s border as part of reunification.

Shen dismissed Bolton’s scheme as “nearly impossible,” but Yun wasn’t as quick to do so. Last year, as Trump peppered North Korea with military threats and Kim Jong Un persisted with nuclear and missile tests, the “Chinese were genuinely convinced that war was imminent,” she noted, and similar ideas about China removing the Kim regime began popping up in Chinese policy circles. Proponents of such ideas, which have not been publicly advocated by Chinese officials, considered the prospect of China getting drawn into a second Korean war and direct conflict with the United States, and “differentiated between the North Korean regime and the North Korean country—determining that North Korea the country remains China’s strategic asset, but the North Korean regime is ... hurting China’s national interests,” Yun said. “So I think John Bolton’s proposal is not inconceivable.” At the moment, however, China’s anxiety about war has subsided and its anxiety about being excluded from nuclear negotiations has swelled. Hence Xi Jinping’s reluctant embrace of Kim Jong Un in Beijing.

While the Trump administration is currently calling for the swift gutting of North Korea’s nuclear arsenal, the Chinese government favors a lengthier and more piecemeal process. The best way to make a denuclearization deal “sustainable” is for it to be “incremental and implemented in parallel” with international security assurances and sanctions relief, Shen explained. This would give the Chinese many opportunities to insert themselves into the negotiations following the Trump-Kim meeting; Yun noted that China would have a key role in providing North Korea with economic aid and energy supplies and in drawing up a peace treaty to end the Korean War and replace the 1953 armistice, to which China was a signatory. She added that China will be carefully monitoring the nuclear talks to make sure North Korea doesn’t “sell China out” like China betrayed the Soviet Union in 1971 by initiating detente with the United States.

The Xi-Kim meeting is a reminder that there is not “a speedy solution to the North Korean nuclear problem,” Yun said—that China is no mere appendage of America’s “maximum pressure” campaign but rather an influential actor with independent interests that must be taken into account.

But Donald Trump just might be up to the challenge. The president’s “belligerent” and “transactional” approach succeeded in swaying China to impose its strictest-ever sanctions on North Korea and in compelling Kim Jong Un to put his almost completed nuclear program up for negotiation, she argued. Trump, Yun told me, “has extracted more cooperation out of China on North Korea than probably all the previous U.S. presidents and administrations combined.”