SEOUL, South Korea (AP) — As close as lips and teeth. Linked by mountains and rivers. A friendship worth more than all the gold in the world.

The clichés come fast when China and North Korea, two masters at national propaganda, get together to glorify their 70-year relationship, which was cemented when China saved an overrun North Korea during the Korean War, and survived the collapse of Communism elsewhere and famine and poverty in the North.

The countries' ties, however, haven't always matched the rhetoric.

This week's meeting between Chinese President Xi Jinping and North Korean leader Kim Jong Un in Pyongyang follows hard efforts to normalize relations that had deteriorated for years while Kim aggressively pursued nuclear weapons and brutally purged members of the North Korean old guard with close ties to Beijing.

Here's a look at the often bitter, sometimes bloody, rarely dull modern history of the neighbors.

___

BONDED BY WAR

North Korea-China ties date to the 1930s when Kim Il Sung, the grandfather of Kim Jong Un, led Korean guerrillas as they fought alongside Chinese soldiers against Japanese colonizers in northeastern China.

The end of World War II drove Japan out of the Korean Peninsula but also split the Koreas into a Soviet-backed North and U.S.-supported South. Moscow installed Kim Il Sung as the leader in the North.

North Korea and China established diplomatic relations in 1949, a year before Kim Il Sung ordered a sneak attack on South Korea, starting a war that killed hundreds of thousands of Chinese troops, though estimates vary, about 37,000 Americans and, by some accounts, 2 million Koreans.

U.S.-led allied forces pushed Kim Il Sung's army deep into North Korean territory before a massive troop intervention by China saved the North from defeat. The fighting stopped in 1953 with an armistice.

After the war, Kim Il Sung played China and the Soviet Union against each other to create more space for his political independence. His consolidation of internal power also involved violent purges of pro-Soviet and pro-China opponents who had unsuccessfully sought to remove him.

In 1961, North Korea and China signed a treaty requiring them to defend each other if attacked; this remains China's only formal military alliance with another country.

In April 1982, China's then-leader Deng Xiaoping traveled to North Korea to attend celebrations of Kim Il Sung's 70th birthday. That set up a visit by Kim to China five months later for discussions on passing leadership to his son, Kim Jong Il, and to reassure Beijing that the North wouldn't tilt toward the Soviet Union in the next generation.

___

SOVIET COLLAPSE, AND NUKES

In 1990, Moscow established diplomatic relations with South Korea in the hopes of attracting investment. This shook North Korea, but things worsened in 1991 when the collapse of the Soviet Union deprived the North of its main economic and security provider.

North Korea turned to China, which saw preventing a North Korean collapse as crucial to its security interests. But their relations became complicated in 1992 when China established diplomatic relations with rival South Korea.

Increasingly shut off diplomatically and with long-running economic failures worsened by a devastating famine that killed hundreds of thousands, North Korea looked to nuclear bombs as a way to ensure its survival.

In 1994, shortly after the death of Kim Il Sung, North Korea reached an agreement with the United States to halt its plutonium production in exchange for energy and food aid. The deal broke down in 2002 after U.S. officials confronted the North over a secret nuclear program based on enriched uranium.

Frustrated over the North's pursuit of nuclear weapons but still preferring a nuclear North Korea over a collapsed one, China drove a multilateral push to resolve the nuclear standoff that collapsed after December 2008 talks.

___

THE KIM JONG UN ERA

Relations between Beijing and Pyongyang were rocky after Kim Jong Un took power following the death of his father, Kim Jong Il, in 2011.

Despite Beijing's opposition, Kim carried out a torrid run of weapons tests while pursuing a nuclear arsenal capable of targeting the U.S. mainland. Kim also executed a slew of senior officials, including his uncle, Jang Song Thaek, who had close ties with China, on treason charges.

China, in turn, supported unprecedentedly harsh sanctions on North Korea that the U.N. Security Council passed in 2016 and 2017, including bans on North Korean exports of coal, textile and seafood, import caps on fuel, and trade bans on vehicles, machinery and "dual-use" technologies that can be used both for civilian and military purposes.

Analysts say the sanctions significantly affected North Korea's economy, which depends on China for more than 90% of its trade, and likely influenced Kim's abrupt turn toward diplomacy in 2018.

Kim traveled to China for his first meeting with Xi in March 2018, which was his first summit with any world leader since taking power. He met Xi three times more in China, before and after his meetings with U.S. President Donald Trump and South Korean President Moon Jae-in, cementing China as a major player in a diplomatic process he seeks to use to leverage his nuclear weapons for security and economic benefits.

Nuclear negotiations between Washington and Pyongyang have stalled since February, when the second meeting between Kim and Trump collapsed because of disagreements over sanctions relief in exchange for disarmament steps.

There are reported signs that China is loosening its crackdown on illegal trade along its border with North Korea as it engages in an intensifying trade war with the United States, which could make Beijing less enthusiastic about supporting the U.S.-led pressure campaign against the North.

While China is unlikely to challenge the U.N. sanctions directly, Xi's visit to North Korea could be followed by large amounts of food, fertilizer and medical aid.

Xi's visit to Pyongyang is the first by a Chinese president since 2005. This fifth summit with Kim means that ties between the countries have been "completely normalized in terms of their traditional, friendly and special relationship," said Park Byung Kwang, an analyst at the Institute for National Security Strategy in Seoul.

Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.