BEIJING — Chinese President Xi Jinping departed Pyongyang on Friday after an elaborate two-day summit in which he encouraged North Korean leader Kim Jong Un to pursue economic development and a political solution to tensions on the Korean Peninsula, Chinese state media reported.

The visit, marked by cheering crowds, dancing children and what Kim described as “the joy of incomparable joy,” was Xi’s first state visit to North Korea. It ended just days before the Chinese leader is set to meet with President Trump during a Group of 20 Summit in Japan.

Some political analysts have interpreted the timing of Xi’s Pyongyang visit as a possible attempt to gain leverage over the United States in a tense trade dispute, though China’s Foreign Ministry this week dismissed that theory as “overthinking.”

The Trump administration’s attempts to persuade North Korea to give up its nuclear weapons program stalled earlier this year after a failed summit.

Both Xi and Kim alluded to the United States during their talks this week, with Xi offering China’s support for a political solution to the clash between Washington and Pyongyang, according to Chinese news agency Xinhua.

Kim said North Korea had taken many steps to avoid tensions but has not received positive responses from “the party concerned,” Xinhua reported, in an apparent reference to the United States. Kim added that North Korea is willing to stay patient, Xinhua said.

Xi also touched on North Korea’s ailing economy, a source of concern to China given their shared border. Beijing wants to avoid a total economic breakdown in the neighboring country and an influx of refugees, according to the U.S. Council on Foreign Relations.

In a speech at a banquet Thursday night, Xi said Pyongyang had “initiated a new strategic line of economic development and improving people’s livelihoods,” and pledged to support both countries’ “common prosperity,” Xinhua reported.

Following the banquet, Xi and his wife, Peng Liyuan, and Kim and his wife, Ri Sol Ju, watched a fireworks show and then a large calisthenics and art performance at the 100,000-seat May Day Stadium, where the audience rose “in thunderous applause and cheers,” Xinhua said.

Behind the stage, a giant LED screen projected slogans, including: “A true camaraderie of trust, an unbreakable friendship unshaken in any storms.” During a dance performance by North Korean children, the screen changed to “Grandpa Xi, so happy to see you!” in Chinese characters.

North Korean orchestras performed patriotic songs, including “Without the Communist Party, There Would Be No New China,” as well as several folk songs that Chinese first lady Peng Liyuan, a professional singer, covered in her albums.

The show ended with another round of fireworks.

“Wherever Xi went, he could feel that China and North Korean peoples are truly as close as family,” Xinhua said.

Lyric Li in Beijing contributed to this report.