By mutual agreement, the reclusive North Korean leader Kim Jong-un’s visit to Beijing and his meetings with President Xi Jinping last week were meant to be kept top secret until he left China.

The Chinese authorities, which equally value secrecy, were happy to oblige. Official media reports about Kim’s visit were not released until he was safely back in his own country on Wednesday morning.

This has given rise to black humour on Chinese social media platforms. One of the better jokes regards the perfect timing of the massive sandstorm that swept much of Northern China, coinciding neatly with Kim’s brief stay from Sunday night to Wednesday.

The sandstorm, which turned the skies darkish yellow and greatly reduced visibility, was said to have been “man made” to prevent US satellites from spotting and targeting Kim’s special dark green train rumbling through China and his motorcade in Beijing.

On a serious note, in this age of social media and camera phones, it is incredibly difficult for the Chinese authorities to keep such a visit secret, despite their great power. As soon as Kim’s armoured train had crossed the Chinese border, rumours and pictures of sightings started to fly on social media platforms.

China’s high-speed trains were delayed to make way for Kim amid heightened security regarding railway tracks and train stations.

The “secrecy” just added a dash of mystery to Kim’s first overseas visit since he took power in 2011, a visit that marked his international debut.

Time to dial down the propaganda as fears of Xi’s personality cult deepen

Although the visit was officially labelled “unofficial”, Xi gave Kim the whole works: a welcoming ceremony with a full military honour guard in the Great Hall of the People, a formal meeting, welcoming banquet, a lunch between the two leaders and their wives, and a night performance of songs and dances.

According to Chinese footage on national television, a beaming Xi told Kim his visit came “at a special time … of great importance”. “We speak highly of this visit,” Xi said.

Indeed, it came amid dramatic developments on the Korean peninsula over the past few months, ahead of a summit between Kim and his South Korean counterpart, Moon Jae-in, in April and a historic summit with US President Donald Trump, possibly in May.

Official accounts of meetings between Xi and Kim struck a very positive note as both countries promised to restore traditionally close ties that have been frayed in recent years. Xi said China would continue to play a constructive role in the denuclearisation of the Korean peninsula and Kim expressed his willingness to meet Trump and discuss denuclearisation.

Their meetings are significant on many levels. By some accounts, Xi executed a masterstroke in pulling off the meeting at a time of tense ties with the United States, helping burnish Xi’s status as world leader.

But Kim – still in his mid 30s – looks like an equal winner, if not the bigger one, out of the meeting, and more importantly, has proved to be a manipulator much more skilful than the outside world gives him credit for. According to official North Korean media reports, Kim disclosed that North Korea first put forward the proposal for him to visit China and expressed appreciation that Beijing had acted quickly to make the trip possible.

A nasty US-China fight is inevitable. But it needn’t be terminal

First, their meetings signalled that China was back at its seat at the head table. Ever since Trump announced this month that he would meet Kim by May, there have been concerns that China is likely to be sidelined and lose its peacemaker status in one of the world’s most explosive issues right on its doorstep. Moreover, ties between the US and China are spiralling downwards over a looming trade war, and US decisions to send government officials to visit Taiwan and warships to patrol the disputed South China Sea. A successful meeting between Trump and Kim would risk driving a wedge into China’s ties with North Korea – ties which have been stressed over the latter’s repeated missile tests and China’s backing of UN sanctions against the regime.

Given China’s historical ties with North Korea, the meeting will definitely ease growing concerns over future relations with North Korea within China’s ruling elites and ordinary people alike.

On Wednesday, editorials released by the People’s Daily and Xinhua news agency, while heaping praise on Xi’s leadership skills, interestingly stressed that the meeting showed Xi’s decisions and strategies on the North Korea issue were “perfectly right”.

On the same day, the Chinese government announced that Yang Jiechi, a politburo member in charge of foreign affairs, would visit South Korea the next day and on Friday, presumably to brief South Korean officials about the meeting and discuss other related matters.

Meanwhile, the White House confirmed that the Chinese government had briefed the Trump administration about the visit and passed “a personal message” from Xi to Trump.

All this has even prompted speculation that China will help facilitate a venue for the Trump-Kim meeting. After all, it is hard to imagine that Kim, worried about his safety and known for his aversion to flights, would risk venturing far from his country, without enough protection.

But Kim is also a sure winner. The meeting with Xi will strengthen his bargaining power ahead of his meetings with Moon and Trump.

Secondly, the meeting signalled that the traditionally close bilateral ties between China and North Korea are back on track. According to Xinhua reports, neither of the leaders mentioned their strained ties and instead talked like old friends. Xi reminisced how the older generations of leaders of both countries trusted and supported each other and paid frequent calls on each other, like relatives. The Xi-Kim meeting was the first since Kim came to power in 2011, soon followed by Xi in 2012.

Why China’s silence on Xi’s term limits move portends trouble

Xi proposed and Kim agreed that they should keep in frequent contact through visits, special envoys and letters to each other.

For his part, Kim said he was “greatly encouraged and inspired” by Xi’s views and promised to work together to bring the bilateral ties to a new level, Xinhua reported.

For the Chinese, the Xinhua reports and the television footage have shown a seemingly deferential Kim in the presence of Xi, the elder statesman, reflecting traditional Asia culture. Xi is turning 65 this year while Kim is 36.

Kim certainly knows how to please Xi, using deferential language. After congratulating Xi on his re-election as party chief and president, Kim said it was his “obligation to come to congratulate Xi in person”.

When they started to talk about the dramatic developments over the peninsula, Kim again used flattery, saying he felt he should come in time to tell Xi in person of the situation “out of comradeship and moral responsibility”.

All this has gone down well not only with Xi and other Chinese leaders but also with ordinary Chinese.

Many Chinese people, including officials, have a romanticised view of ties with North Korea because of the long historic connections in which North Korea was a tributary state in China’s feudal dynasties and also because China sent millions of PLA soldiers to fight the Americans during the Korean war in the 1950s. They view North Korea as a little brother who should be deferential to the big brother.

But such views are fallacies. Historically, Korea was a tributary state but Koreans’ independent streak always remained strong. Even after the Korean war, in which hundreds of thousands of Chinese soldiers died fighting for the Kim family, the Kims were never beholden to the Chinese. Kim’s father and grandfather were skilful operators in playing off China and the former Soviet Union to their own advantage, whether in terms of securing weapons, food supplies and other help, or sweet talking more territory from China.

As China beats its war drum, who should hear its call?

Despite his relatively young age, he himself has proved a ruthless and skilful dictator – from purging the old guard from his father’s era to having his uncle and elder brother killed to reduce the influence from China. The latter two were known for friendly ties with China.

As Kim has ruled his country with an iron fist and kept it closed to the outside, he is mostly described in overseas media as a trigger-happy mad man, a deadly menace to the rest of the world.

This has not been helped by the war of words between Kim and Trump. Trump famously described him as “a rocket man” and Kim returned the favour, calling Trump a “mentally deranged US dotard”.

However, Kim’s international debut in Beijing shows there is much more to him than meets the eye. He came across as confident and mature and willing to compromise – all in all, looking like an astute player in this complex and potentially explosive game of geopolitical chess.

Wang Xiangwei is the former editor-in-chief of the South China Morning Post. He is now based in Beijing as editorial adviser to the paper