North Korean leader Kim Jong Un was treated to a lavish welcome by Chinese President Xi Jinping during a secretive trip to Beijing as both sides seek to repair frayed ties ahead of landmark summits with Seoul and Washington.

On his first trip abroad since taking power, Kim and his wife were met with honour guards and a banquet hosted by Xi, according to state media, which confirmed the ‘unofficial’ visit on Wednesday only after Kim had returned to North Korea.

The two men held talks at the stately Great Hall of the People during which they hailed their nations' historic relations, with Kim pledging that he was ‘committed to denuclearisation’ on the Korean peninsula, according to China's Xinhua news agency.

‘There is no question that my first foreign visit would be to the Chinese capital,’ Kim said, according to North Korea's official KCNA news agency.

‘This is my solemn duty as someone who should value and continue the DPRK-PRC relations through generations.’

KCNA said Xi accepted an invitation to visit Pyongyang, which would be his first trip to the North Korean capital since he took power in 2012.

The two men had not met since Kim took over after the death of his father, Kim Jong Il, in 2011, and relations have been strained as China has backed a raft of UN sanctions against Pyongyang over its nuclear and missile tests.

But Xi underscored the importance of developing ties, saying it was ‘a strategic choice and the only right choice’ and that he was willing to maintain frequent contact with Kim ‘under the new circumstances’, according to Xinhua.

Xi and Kim shook hands and sat across from each other at a long conference table, both flanked by officials, at the Great Hall of the People, according to television images which showed the North Korean leader taking meticulous notes.

Later, Xi and his wife, Peng Liyuan, waved goodbye while Kim and his spouse, Ri Sol Ju, smiled as they left in a black car.

Chinese and North Korean state media said the visit started Sunday and ended Wednesday.

Analysts said Xi likely wanted to see Kim to ensure North Korea does not cut a deal with US President Donald Trump that hurts Chinese interests during a summit expected to be held in May.

Beijing had appeared sidelined by Pyongyang's approaches to Seoul and Washington, but Kim's visit puts China firmly back at the centre of the diplomatic game.

‘It shows that at this crucial juncture, Kim and Xi believed that it was time to seize the opportunity to consult,’ Bonnie Glaser, a China expert at the Washington-based Center for Strategic and International Studies, told AFP.

‘Both likely concluded that further deterioration in relations would be harmful.’

Deng Yuwen, an independent Chinese international relations scholar, said North Korea needed to turn to its old ally ahead of the US summit, as Kim will be sceptical that Trump will guarantee the security of his regime.

‘North Korea needs the big brother to protect it at a crucial moment,’ Deng said.

- Trump informed -

Xinhua said Kim expressed his willingness to hold summits with Trump and South Korean President Moon Jae-in.

‘The issue of denuclearisation of the Korean Peninsula can be resolved, if South Korea and the United States respond to our efforts with goodwill, create an atmosphere of peace and stability while taking progressive and synchronous measures for the realisation of peace,’ Kim said, according to Xinhua.

South Korea said last month after talks with Kim in Pyongyang that he would consider abandoning his nuclear weapons in exchange for US security guarantees, and flagged a halt to weapons tests while talks were under way.

White House spokeswoman Sarah Sanders said Trump received a personal note from Xi about Kim's visit on Tuesday.

‘We see this development as further evidence that our campaign of maximum pressure is creating the appropriate atmosphere for dialogue with North Korea,’ Sanders said.

Confirmation of the visit ended 24 hours of speculation about the identity of a mysterious North Korean visitor after Japanese media spotted a green train, similar to the one used by Kim's father, arriving in Beijing on Monday and departing the following day.

During the news blackout, a heavy police presence at key venues, barricades and mysterious motorcades hinted at his presence.

North Korea's official Rodong Sinmun newspaper on Wednesday featured photos of Chinese officials greeting Kim and his wife with flowers at the train station, and his motorcade being escorted by police motorbikes in front of the Forbidden City.

- Frayed ties -

His visit to China came as a surprise given the state of relations between the Cold War-era allies, which fought together in the 1950-53 Korean War.

China chaired six-party talks on North Korea that collapsed a decade ago, but its calls to revive that forum have not been heeded so far and Beijing appeared to be on the margins when South Korea announced that Kim had offered to meet with Moon and Trump.

Frustrated by its neighbour's nuclear weapons programme and under pressure from Trump, China has used its economic leverage to squeeze Kim's regime.

At the same time, Beijing fears the collapse of the regime in Pyongyang and the instability it would bring, potentially sending waves of refugees into China and the possibility of US troops stationed on its border in a unified Korea.

But Kim's visit appears to have put relations appear back on track, with Xi inviting Kim and his wife to visit China again.