North Korea’s weekend missile test is an immediate leadership test for Moon Jae-in, who was elected South Korea’s new president just last week. Moon, who predicated his campaign on engaging, not isolating Pyongyang, now must react to North Korean claims that the intermediate-range ballistic missile can carry a heavy nuclear warhead.

President Trump, who rightly views the growing North Korean arsenal as a direct threat not just to East Asia but to the United States, should work closely with Moon to ensure that any emerging divisions between Washington and Seoul don’t derail the imperative to denuclearize North Korea.

While North Korean provocations played a part in the election, domestic dynamics took on perhaps even a bigger role. Like voters in Western democracies, South Koreans are worried about economic conditions. But looming even larger was a corruption scandal that led to the impeachment of Moon’s presidential predecessor, Park Geun-hye.

Park’s hard line on North Korea would have meshed well with Trump’s stated goals on Pyongyang. This included the instillation of the Terminal High Altitude Area Defense (THAAD) anti-missile system that was strongly opposed not only by North Korea but also by China, whose leaders viewed it as a check on its growing military capabilities.

Moon questioned, and then equivocated, on THAAD, but was given a campaign issue when Trump unexpectedly and unnecessarily suggested that South Korea pay for the U.S. system. The unforced error on Trump’s part helped boost a candidate who appears to favor rapprochement with North Korea.

Previous efforts at coaxing North Korea not only haven’t worked but exacerbated the problem. In particular the “Sunshine Policy” of the late 1990s and early 2000s gave Pyongyang badly needed cash that it used not for its besieged citizens but for developing weapons. Moon favors reopening a joint North-South industrial zone that might repeat the mistake at a time when the North’s weapons program is accelerating in defiance of U.N. resolutions.

Diplomacy is still the preferred and perhaps only possible way to solve this spiraling crisis. But that demands unity among the U.S., its Asian allies, China, and Russia. This will be a true test of Trump’s ability to lead with diplomacy.

For his part, Moon must not distance his nation too far from its longtime protector, and may find events diplomatically determinative. “He will probably not be able to separate or build more space into the U.S.-Korea alliance as he wanted to,” Lisa Collins, a fellow in the Korea Chair Program at the Center for Strategic and International Studies, told an editorial writer. “He will find very quickly because of what North Korea is doing with missile testing, and perhaps another nuclear test, that he will have to work very closely with the U.S. in the alliance structure.”

Global security depends on that alliance, and it’s imperative that Trump and Moon are up to the task.