BEIJING - North Korea's leader Kim Jong Un and his Chinese counterpart Xi Jinping sought to portray strong ties between the neighbours and long-time allies despite a recent chill, as both countries on Wednesday confirmed Kim's secret trip to Beijing this week.

China's official Xinhua News Agency said Kim made the unofficial visit to China from Sunday to Wednesday at Xi's invitation in what was in his first trip to a foreign country since he took power in 2011.

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.

Official reports from both countries depicted in effusive terms warm ties between the two leaders in what analysts said appeared to be an effort to downplay recent tensions in relations over Kim's development of nuclear weapons and long-range missiles.

In these reports, "Kim reaffirms the traditional friendship between the two countries as if nothing had ever happened, when the relationship had plummeted to unprecedented lows," said Bonnie Glaser, an Asia expert at the Center for Strategic and International Studies.

Ties in recent months have frayed as China supported tougher UN sanctions on North Korea and suspended imports of coal, iron ore, seafood and textiles. Pyongyang last year seemingly sought to humiliate Beijing by timing some of its missile tests for major global summits in China, while its state media accused Chinese state-controlled media of "going under the armpit of the U.S." by criticizing the North.

Xi hailed Kim's visit as embodying the importance with which the North Korean leader regarded ties with China.

"We speak highly of this visit," Xi told Kim, according to Xinhua.

For China, the visit also reminds other countries that Beijing remains one of North Korea's most important allies and is a player not to be sidelined in denuclearization talks. It also projects to the Chinese public that Xi is firmly in charge of steering Beijing's relations with North Korea in a way that favours China's interests.

"Here is Xi Jinping saying, 'Don't worry, everything is going to be great'," Glaser 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 Donald Trump in the coming weeks. China would also not want Kim's first foreign meeting to be with someone other than Xi.

"China was clearly not comfortable with the idea of Kim meeting with Moon and Trump before having ever met with Xi," said Paul Haenle, director of the Carnegie-Tsinghua Center for Global Policy in Beijing.

"Beijing has significant interests and huge stakes in any outcomes of upcoming summits and did not want to be on the sidelines as a spectator" as important diplomatic events occurred, Haenle said.

Kim was described by Xinhua as saying that his country wants to transform ties with South Korea into "a relationship of reconciliation and co-operation." The two Koreas are still technically at war because their 1950-53 war ended in an armistice, not a peace treaty.

Kim also said that North Korea is willing to hold a summit with the United States, according to Xinhua.

North Korea's official Korean Central News Agency published Kim's personal letter to Xi dated on Wednesday, where he expressed gratitude to the Chinese leadership for showing what he described as "heartwarming hospitality" during his "productive" visit.

Kim said that the first meeting between the leaders of the two countries will provide a "groundbreaking milestone" in developing mutual relations to "meet the demands of the new era." Kim also said that he's satisfied that the leaders confirmed their "unified opinions" on mutual issues.

"For the North Koreans, it is in their best interests to enter any meetings with Moon or Trump having shored up and repaired to a certain extent their relations with Beijing," Haenle said.

The North's diplomatic outreach this year follows a tenser 2017 when it conducted its most powerful nuclear test to date and tested three intercontinental ballistic missiles designed to target the U.S. mainland.

The developments are being 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.

In a speech at a banquet in China, Kim described the traditional allies as inseparable "neighbouring brothers" with a relationship moulded by a "scared mutual fight" to achieve socialist ideals, according to KCNA.

In addition to the trip being his first abroad as leader, his talk 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 that December.

"It's most proper that my first overseas trip would be the capital of the People's Republic of China as it's also one of my noble duties to value the North Korea-China friendship as I do my own life and extend it (for another generation)," said Kim, according to the North Korean agency.

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.

-----

Associated Press writer Foster Klug in Seoul contributed to this report.