North Korean leader Kim Jong-il told China's leaders he would be patient, flexible and engaged in six-party talks on his nuclear programmes, saying what they hoped to hear in an unannounced three-day visit ending on Wednesday.
Shortly after the reclusive leader of the North boarded a train bound for home on Wednesday afternoon, China's state media broke a news blackout to show footage of a smiling Kim sharing bear hugs with China's top leaders.
Kim was "satisfied" with results of his unofficial visit at the invitation of Chinese President and Communist Party chief Hu Jintao and the two sides reached consensus on the nuclear issue, the official Xinhua news agency said.
His rare overseas trip came a week after US Vice President Dick Cheney visited China with new evidence of the North's possession of nuclear arms and warning that time was running out to end the stalemate.
"The DPRK side will continue to take a patient and flexible manner and actively participate in the six-party talks process, and make its own contributions to the progress of the talks," Xinhua quoted Kim as telling Hu.
North Korea "sticks to the final nuclear-weapon-free goal and its basic position on seeking a peaceful solution through dialogue has not changed", it said. DPRK stands for Democratic People's Republic of Korea, which is the North's official name.
Kim gave long hugs to Hu, Central Military Commission chairman Jiang Zemin and Premier Wen Jiabao. He shook hands with a slew of other top leaders in meetings Xinhua described as "cordial, friendly and candid".
During a trip shrouded in secrecy, Kim visited a model high-income farm, dined on Peking duck and went to the municipality of Tianjin, an hour-and-a-half drive from Beijing.
China's nightly state television news devoted 12 minutes - an unusually large block of time - to Kim, showing him toasting hundreds of guests at a banquet and waving from the window of his green train as it readied to depart.
Choi Choon-heum, a senior fellow at the Korea Institute for National Unification, said the fact that the visit was unofficial indicated it was a result of strong demands by China.
"The two countries emphasised the closeness of the bilateral relationship. I think that part means Kim asked for more economic assistance from China and that it will lead to more Chinese economic support," he said.
"In return, I think Kim will accept some of China's terms, such as the fast establishment of working group talks. North Korea indirectly expressed agreement with China's initiative."
At the last round of six-way talks in February, the parties agreed to set up working groups before the next round, but nothing has happened since. Diplomats have said hopes were fading that working groups could meet this month.
South Korea's foreign ministry said Seoul hoped Kim's visit would "contribute to peace and stability on the Korean peninsula, dialogue and co-operation between the South and the North and to a peaceful resolution of the North Korean nuclear problem".