SHENYANG, China—The Pentagon’s top general on Wednesday said he discussed with his Chinese counterparts ways to coordinate with China’s military to avoid dangerous miscalculations should war break out with North Korea.

Gen. Joe Dunford, chairman of the Joint Chiefs of Staff, described the contingency talks after he paid a rare visit to the Chinese military command that oversees the North Korean border, viewing live-fire drills and sharing lunch with People’s Liberation Army troops.

He said the discussion took place on Tuesday, when he also signed an agreement with his Chinese counterpart to formalize and increase operational communication between the U.S. and Chinese militaries.

The talks indicate that alarm on both sides over the tensions surrounding North Korea’s advancing nuclear and missile programs are pushing Washington and Beijing to set aside some of their mutual distrust and deepen military-to-military communication, analysts and diplomats said.

Gen. Dunford’s trip was planned long before a series of tit-for-tat threats flared in recent days between U.S. President Donald Trump and North Korean leader Kim Jong Un. United Nations Secretary General Antonio Guterres on Wednesday said tensions on the Korean Peninsula are the highest levels in decades and urged a resumption of talks.