SEOUL — South Korean President Moon Jae-in must keep up a delicate balancing act between two unpredictable leaders: the one with nukes in the North, and the one in Washington who leads his country’s closest ally.

But Moon — newer in office even than President Trump — appears to be managing that feat. This week, he has ushered in the first positive news related to North Korea in years, responding to an overture from Kim Jong Un and, on Wednesday, very diplomatically giving much of the credit to Trump. 

“I give President Trump huge credit for bringing about the inter-Korean talks, and I’d like to thank him for that,” Moon said at a news conference in Seoul. 

Moon’s remark came in response to a question about Trump’s Saturday tweet that the talks were taking place because he was “firm, strong and willing to commit our total ‘might’ against the North.” 

Trump has been calling for “maximum pressure” on North Korea and has sometimes suggested that military action might be needed.

Moon said the fact that North Korea returned to talks — albeit about the Olympics, not about its nuclear weapons program — could be the result of U.S.-led sanctions and pressure. 

He assured the United States that South Korea would not act out of step with the international community regarding any sanctions relief that might be needed to facilitate North Korea’s attendance at the Winter Olympics in the South next month.

Yet with the agreement, however modest, Moon has managed to alter the narrative that North Korea cannot be reasoned with.

Moon has dubbed the games the “Peace Olympics” and desperately wants North Korea to attend. 

“South Korea is not intending to ease sanctions on North Korea unilaterally and separately from the international sanctions,” said Moon, who was elected in a landslide victory last May after the impeachment of disgraced President Park Geun-hye.  

After nine months in office, Moon enjoys strong support from the South Korean public, with most polls putting his approval ratings in the 70s.

His government has been going to great lengths to avoid antagonizing the American president, who has been capricious on issues including the South Korea-U.S. trade deal. 

But Moon, a liberal who favors engagement with Pyongyang, also needed to make nice with Kim. 

This is partly because Moon wants to minimize the gap between North and South, but also because he wants to fend off suggestions from some in Washington that military action might be needed as a lesson to Pyongyang.

Trump’s national security adviser, H.R. McMaster, suggested at the end of last year that time was running out to deal with North Korea.

A military strike on North Korea would have devastating consequences for South Korea. About 25 million people — half of South Korea’s population — live within range of the North’s conventional artillery, and among them are tens of thousands of Americans. 

Moon has resolutely opposed any military action and has warned that no strike must take place without his approval — although these are not the terms of the South Korean security agreement with the United States.

Tuesday’s talks were the immediate result of Kim’s New Year’s Day pronouncement that North Korea would be willing to send a delegation to the Winter Games set to open Feb. 9 in PyeongChang, 40 miles south of the border between the Koreas.

As many as 500 North Koreans — including senior officials, athletes, cheering and performing-arts squads, taekwondo teams and journalists — are expected to attend. The exact makeup of the delegation is under discussion.

Moon said he was “open to any form of meeting, including a summit” with Kim to help improve inter-Korean relations and to make progress on the nuclear issue, although he said he was not interested in “talks for the sake of talks.”

But there is significant skepticism after Tuesday’s tentative agreement on Olympic participation and the resumption of inter-Korean military talks.

Army Gen. Vincent K. Brooks, commander of U.S. Forces Korea, said it was “notable” that North Korea had taken this step but that caution was warranted.

“What is the motivation? We don’t know,” Brooks said in a speech in Seoul. “We will have to see that over time.”

Some analysts think that Kim is looking to drive a wedge between South Korea and the United States, exposing a gap in their alliance.

“Kim Jong Un wants to break the chain of international pressure against North Korea,” said Nam Sung-wook, a former intelligence think tank chief now teaching at Korea University. “And the weakest link in that chain is South Korea.”

This has been a classic North Korean strategy in previous years, when the Kim regime has appealed to its “brethren” in the South to try to weaken the united front against it.

But John Delury, a professor of international relations at Yonsei University in Seoul, said it was wrong to write Moon off as naive or as someone who can be manipulated by Kim.

“Moon is not trying to claim any of the credit here. He’s giving it to Kim for suggesting these talks in his New Year’s Day speech and to Trump for his tough talk,” Delury said. “This is because Moon has embarked on a patient and steady diplomatic track.”

Yoonjung Seo contributed to this report.