For Chinese President Xi Jinping, the meeting with a long-troublesome neighbour ensures Beijing will not be left out of any deal struck between the United States and North and South Korea, experts said.
Months of frosty relations between Beijing and Pyongyang appeared suddenly to thaw with Kim's secretive trip, which saw the Chinese capital go into security lockdown as the mysterious North Korean delegation toured the city.
China said Kim had pledged to denuclearise the Korean peninsula while North Korean state media said Xi had accepted "with pleasure" an invitation to visit the North.
Kim's meeting with Xi strengthens North Korea's negotiating position by aligning the two nations ahead of Trump and Kim's planned meeting, said Wang Peng, a North Korea expert at the Charhar Institute in Beijing.
"North Korea is seeking assurances," he said. "They want to quickly mend ties with China so that they have more leeway with the Unites States and they have more confidence in a good outcome."
Analysts say North Korea has been hurt by tightening UN sanctions and would need Beijing's support for any softening of trade restrictions.
China wanted to show its importance as a partner to North Korea and ease worries about being sidelined in negotiations between North and South Korea and the United States.
"At the end of the day, China's got huge interests and it was not comfortable not being at the table," said Paul Haenle, director of the Carnegie-Tsinghua Center in Beijing and a White House representative to the Six Party Talks from 2007-09.
"Kim Jong Un's first meeting with a head of state was with the Chinese president, which frankly from the Chinese perspective is exactly the right thing," he added.
Trump's decision to hire hardliners such as incoming National Security Adviser John Bolton may have put added pressure on North Korea before the summit, said Han Suk-hee, professor of Chinese Studies at Yonsei University.
"It seems that North Korea is not ready to deal with the United States without support and help from its longtime ally China," he said.
China, as well as being North Korea's biggest trade partner, also has key strategic interest in assuring its isolated neighbour remains a buffer between it and South Korea, home to 28,500 US troops.
The two nations also have long-standing emotional and historic ties. China sometimes says they are "blood brothers", having fought side-by-side in the 1950-53 Korean War.
The two remained close allies in the decades immediately after the Korean War, but have drifted apart since Kim succeeded his late father.
North Korea's rapid escalation of nuclear tests and missile launches, combined with the assassination of Kim's half-brother last year in a Kuala Lumpur airport, brought diplomatic ties between Beijing and Pyongyang to historic lows.
"China is ... the only state willing and able to immediately ease North Korea's economic burden," said Christopher Green, senior adviser at International Crisis Group. North Korea was not prepared to give up its close relationship with China, much as it may chafe at its economic and political reliance on its much bigger neighbour, he added.
With North and South Korean relations improving during the Winter Olympics and plans for summits involving Trump, Moon and Kim, Beijing had reasons to resume contact with North Korea that had all but disappeared in the past year.
Xi stressed to Kim that past Chinese and North Korean leaders had always visited each other "as often as relatives", proposing the two leaders set up new channels of communication, China's official Xinhua news agency reported on Wednesday.
Chinese state media has cast Beijing as crucial to forcing talks between Trump and Kim with its "freeze for freeze" pitch for North Korea to suspend nuclear and missile tests, and South Korea and the United States to suspend military drills.
"It's extremely difficult for the US to map out a feasible denuclearisation process that meets the North Korean preconditions without China's support and involvement," said Cheng Xiaohe, a North Korea expert at Renmin University in Beijing. "China wants to show it cannot be left out."
A Friend In Need
Speaking at a banquet hosted by Xi, Kim Jong Un expressed gratitude to China for readily accepting his proposal to visit and all the efforts Chinese leaders made to pave the way for a successful visit in a short period of time, according to the North's official KCNA news agency.
China remains an advocate for a dual track of pressure and greater dialogue with North Korea, a position at odds with the Trump administration's maximal pressure approach.
That disagreement had left Beijing sidelined amid the escalating crisis, shunning a meeting of foreign ministers in Canada where leaders discussed how to pressure the North into backing down.
North Korea may also be taking advantage of tensions in US-China relations over trade and the disputed South China Sea to draw in Beijing, Jia Qingguo, dean of the School of International Studies at China's Peking University
"China wants North Korea to denuclearise but does not want to alienate North Korea at a time when China-US relations are deteriorating very fast," said Jia, who has advised the government on foreign policy.
"We want a denuclearised North Korea, but at the same time we want North Korea to be a friend."