BEIJING — North Korean leader Kim Jong Un made a surprise trip to China this week, meeting Chinese President Xi Jinping ahead of planned summits with South Korean and U.S. leaders, Chinese and North Korean state media confirmed Wednesday.

The journey, which is believed to be Kim’s first foreign trip since he came to power in 2011, adds a new piece to a complex diplomatic puzzle over the future of North Korea’s nuclear program.

The announcement ends a mystery that started Monday, when a mysterious train chugged into central Beijing, spurring reports of a high-profile visitor from North Korea.

The North’s official Korean Central News Agency confirmed that the visitor was indeed Kim, along with his wife, Ri Sol Ju, arriving for an “unofficial” visit at the invitation of the Chinese president, Xi Jinping. The confirmation came sometime after the North Korean group is believed to have departed China.

Kim traveled with all his top aides, KCNA said, including Choe Ryong Hae, often called the No. 2 leader of North Korea and the head of the powerful Organization and Guidance Department, and Ri Su Yong, the former ambassador to Switzerland and foreign minister, who is now a top official in the Politburo.

China and North Korea have had close ties for decades, but in recent years, the relationship has been stressed. Kim’s visit suggests an effort to repair relations ahead of Kim’s planned meetings with the South’s president, Moon Jae-in, and then President Donald Trump.

Chinese and North Korean accounts of the meeting struck a positive tone. “We speak highly of this visit,” Xi told Kim, according to Chinese state media.

Kim’s toast to Xi: “It is appropriate that my first trip abroad is in China’s capital, and my responsibility to consider continuing NK-China relations as valuable as life,” according to KCNA.

The question of who was on the armored train had gripped the Chinese capital for days. The train arrived unannounced. Passengers disembarked and boarded limos. After nightfall, a motorcade drove to a state guesthouse where foreign dignitaries often stay.

But Chinese officials and media and the South Korean government were initially quiet about the identities of those who had been aboard.

Chinese netizens looking for answers hit a wall. On Tuesday, three of the top 10 blocked terms on Weibo, a microblogging site, were “Kim Jong Un,” “North Korea” and “Fatty the third,” a popular Chinese nickname for Kim, according to, a website that tracks censorship.

White House Press Secretary Sarah Huckabee Sanders responded to the news of Kim’s visit by saying that the Chinese government had briefed the Trump administration about the visit Tuesday. The briefing included a “personal message from President Xi to President Trump,” she said.

The Trump administration sees the development “as further evidence that our campaign of maximum pressure is creating the appropriate atmosphere for dialogue with North Korea,” Sanders said.

Chinese experts said a visit by a senior North Korean leader before the meetings with Moon and Trump made sense.

“At a possibly historic moment, before the start of a dramatic play on the Korean Peninsula, China was losing the spotlight,” said Cheng Xiaohe, a North Korea expert at Beijing’s Renmin University. A visit would restore Beijing’s leading role, he reasoned.

Zhang Liangui, a retired professor and Korea scholar at the Central Party School in Beijing, said, “The North Korea nuclear issue cannot be solved by solely relying on negotiations between North Korea and the United States, because, essentially, the nuclear issue is a regional security issue, not an issue of the relationship between North Korea and the United States.”

Experts also said secrecy was standard for North Korean visitors. “Kim Jong Un’s father, Kim Jong Il, employed a similar approach in the past,” said Lu Chao, a Korea expert at China’s Liaoning Academy of Social Sciences. “It’s usually a secret visit and then publicized after the North Korean leader has left.”

It was the example of Kim Jong Il’s 2011 visit that provided early clues that something was up.

The detective work started Monday when trainspotters and North Korea watchers noticed two suspicious developments: tight security at the China-North Korea border and train delays across the northeast.

On Monday afternoon, Japanese broadcaster NTV spotted an unusual train pulling into a station in the heart of the capital. It was green and yellow and looked a lot like the trains used by Kim Jong Il in 2011.

As the news started to spread, so did unverified videos of a motorcade speeding through the Chinese capital. Soon, unconfirmed reports of Kim sightings were spreading in chat groups.

Washington Post writers Anna Fifield, Amber Ziye Wang, Shirley Feng, Luna Lin, Yang Liu, Min Joo Kim and Yuki Oda contributed to this report.

Follow the Bangor Daily News on Facebook for the latest Maine news.