By Jane Perlez, New York Times–

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.

“Beijing likely would want to ensure that Pyongyang would not develop a closer relationship with Washington than Beijing,” said Zhao Tong, a North Korea expert at the Carnegie-Tsinghua Center for Global Policy in Beijing. “The visit by the Chinese foreign minister, the first in 11 years, appears to be part of that effort.”

Beijing has suspected that Washington might agree to put aside its nuclear disagreements with North Korea and accept the North’s nuclear capabilities if it served to contain China, he said.

Mr. Wang could have delivered a careful message, reminding the North that China was its true friend despite the rough patch in the past six years since Mr. Kim came to power, said Xia Yafeng, a Chinese historian at Long Island University.

“Wang Yi had a mission: to coordinate with the North Koreans on how to talk with Trump,” he said. “He can advise the North Koreans, but he cannot threaten them. He may say: ‘Be careful when you talk with Trump. We will always side with you.’”

China grudgingly went along with Washington’s demand last year that it support United Nations sanctions meant to deny the North of critical foreign currency from sales of coal, minerals, seafood and garments.

But Beijing’s desire to punish North Korea’s economy is probably wavering, Mr. Zhao said.

“I can imagine China taking additional measures to further improve ties with North Korea,” Mr. Zhao said. These would include working to connect North Korea to roads and rail networks in northeast Asia, and embracing the North in its Belt and Road Initiative.

There are already signs that China is trying to loosen some of the economic restrictions. Businessmen in the area of northeastern China that borders North Korea say that some North Korean workers are returning to China on short-term visas, and that they expect trade to pick up soon.

“I can imagine China already starting studies into options to increase economic cooperation with North Korea in areas that would not violate existing United Nations Security Council resolutions,” Mr. Zhao said.

Beijing was miffed and surprised at being pointedly excluded from several items in the joint declaration that North and South Korea issued last Friday at the end of their summit meeting.

The two Koreas said they would start talks with Washington to negotiate a peace treaty to formally end the Korean War, which ravaged the peninsula from 1950 to 1953.

The declaration mentioned “trilateral or quadrilateral” talks. If the talks were “trilateral” that would include North and South Korea and the United States but not China, which sent millions of troops to fight on North Korea’s side during the war. China withdrew all its troops in 1958.

“The Chinese heard it was South Korea that got the talks to be broadened to quadrilateral,” said Paul Haenle, director of the Carnegie-Tsinghua Center for Global Policy.

Beyond that, China was not invited to send observers to the planned destruction of the Punggye-ri nuclear test site in North Korea at the end of this month. Mr. Kim said he would invite South Korean and American experts to witness the shutdown, a gesture that American officials said would have little impact on the North’s nuclear and ballistic missile programs.

“The test site is close to the Chinese border,” Mr. Haenle said. “The Chinese were upset because China is a nuclear power, South Korea is not.”

Despite these snubs, the visit of the foreign minister, Mr. Wang, was symbolically important, Mr. Xia said.

In the heyday of the China-North Korea relationship when Mr. Kim’s grandfather, Kim Il-sung, was in power, top-level visits between the two countries were frequent. The grandfather visited China many times, Mr. Xia said. Even Kim Jong-un’s father, Kim Jong-il, made seven trips between 2000 and 2011.

The parade of visits stopped after the young Mr. Kim came to power and derailed the relationship to China by ordering the killing of senior Korean officials close to Beijing.

Mr. Kim made a surprise visit to Beijing in late March, apparently on his own initiative, maneuvering in a way that made him look less like a supplicant and more like an equal.

Mr. Trump’s meeting with Mr. Kim is likely to take place in the Demilitarized Zone at the border between South and North Korea, Mr. Trump has said. Some diplomats are speculating that the two leaders may meet on the northern side of the zone, drawing a distinction with the summit meeting last week on the South Korean side, and satisfying Mr. Trump’s desire for drama.

China’s president, Xi Jinping, is expected to go to Pyongyang after the Trump-Kim meeting. One of the foreign minister’s duties was to confirm details of Mr. Xi’s visit, Chinese analysts said.