BEIJING —The Chinese government confirmed Wednesday that North Korea’s reclusive leader Kim Jong Un went to Beijing and met with Chinese President Xi Jinping in his first known trip to a foreign country since he took power in 2011.

The official Xinhua News Agency said Kim made an unofficial visit to China from Sunday to Wednesday.

Xi held talks with Kim at the Great Hall of the People in Beijing and he and his wife Peng Liyuan hosted a banquet for Kim and his wife Ri Sol Ju, Xinhua said. They also watched an art performance together, the news agency said.

Analysts say Kim would have felt a need to consult with his country’s traditional ally ahead of his planned meetings with South Korean President Moon Jae-in and President Trump.

The North’s diplomatic outreach came after an unusually provocative year when it conducted its most powerful nuclear test to date and three ICBMs tests designed to target the U.S. mainland.

The developments were interpreted as the North being desperate to break out of isolation and improve its economy after being squeezed by heavy sanctions.

China remains North Korea’s only major ally and chief provider of energy, aid and trade that keep the country’s broken economy afloat.

The visit to China marks Kim’s first known trip since taking power in 2011 and his reported meeting with Xi was his first meeting with a foreign head of state.

Kim’s father, late North Korean leader Kim Jong Il, visited China several times during his rule, lastly in May 2011, months before his death.

Past visits by Kim Jong Il to China were surrounded in secrecy, with Beijing only confirming his presence after he had crossed the border by train back into North Korea.