BEIJING — As North Korea holds summit meetings with its archenemies — first South Korea, and soon the United States — China is hustling not to lose influence.

Its foreign minister, Wang Yi, returned Thursday to Beijing after two days in North Korea’s capital, Pyongyang, where he met with the country’s leader, Kim Jong-un, shoring up China’s position as the North’s best friend.

China holds substantial economic leverage, but in the heightened strategic competition between it and the United States, it worries that Mr. Kim is using that rivalry to reduce dependence on China, his country’s longtime benefactor.

One of Mr. Wang’s jobs was to try to stop Mr. Kim from veering toward the United States under President Trump, some Chinese experts said.