North Korea is in the headlines - again. For a small, poor country of 25 million people, it sure does make a lot of news. This time it's the perennial issue of nuclear testing. North Korea has tested five nuclear devices since 2006. Donald Trump is in no mood to allow a sixth.

Just days before his Florida summit with Chinese President Xi Jinping, Trump vowed that "if China is not going to solve North Korea, we will." Then, just after the summit, he backed up his pledge by ordered an aircraft carrier strike group to the region.

Most people agree that North Korea is a problem. Aside from its nuclear tests, it also stands accused of state-sponsored counterfeiting of foreign currencies, the industrial-scale manufacture and sale of illicit drugs, and even of assassinating its own citizens in foreign countries.

But why is North Korea China's problem in particular? China is North Korea's only major diplomatic ally, but the relationship is fraught with difficulties. How did China get saddled with such a troublesome partner? The history of the relationship runs much deeper than most people realise.

The first Korean War

China fought in the Korean War of 1950-53. In 1950, the new communist regime in China invaded the country with nearly three million troops, losing some 180,000 soldiers in the war. All this happened barely a year after the end of China's own civil war in 1949.

China didn't participate in North Korea's initial invasion of the South. It intervened after Douglas MacArthur's United Nations troops defeated the North Koreans and launched a counter-invasion of the North. The UN army was virtually on the border with China before China unexpectedly invaded and pushed south to the line that still divides the two Koreas to this day.

The last thing China wants is a united Korea under South Korean leadership.

But the 1950-53 Korean War wasn't the first Chinese intervention in Korea. In a distant precursor to the 1950s, a very similar drama played out way back in the 1590s.

In 1592, Japan invaded Korea at Busan and rapidly drove up the peninsula to the Chinese border, prompting an intervention from China. The Chinese army pushed the invaders back south, liberating Pyongyang but reaching a stalemate just north of Seoul, roughly where the demilitarised zone stands today. The conflict ended with a negotiated withdrawal of Japanese troops in 1593.

Japan went on to invade Korea again in 1597, but Korean forces repelled the attack with Chinese support. For the next three hundred years, Korea was a kind of a Chinese protectorate, first as China's closest "tributary" state and later as an ally in the resistance against Western and Japanese colonialism.

READ MORE: North Korea and mounting tensions - the view from Seoul

In 1894, Japan invaded Korea again, this time as part of the larger 1894-95 Sino-Japanese War. And again Chinese troops made their major stand at Pyongyang. But this time they lost, and by 1910 Korea lost its independence entirely. It became a colony of Japan and suffered a 25-year military occupation which poisons Japanese-Korean relations to this day.

Back to Pyongyang

Having fought to hold Pyongyang in 1593, 1894, and 1951, China's connection with North Korea long predates the current communist regimes in both countries. In fact, it is older than communism itself. North Korea is not exactly a protectorate of China, but its history is so tightly intertwined with China's that its independence of Beijing is almost unthinkable.

Today's North Korean regime has become such a liability to China that China may finally have lost its patience. In late February, China banned imports of coal from North Korea, an act applauded by US President Donald Trump. Now things seem to be getting more serious.

There have been unconfirmed reports that China has moved up to 150,000 troops to its border with North Korea, which Beijing has called "pure fabrication". But on Friday, China did suddenly suspend flights between Beijing and Pyongyang without offering any explanation.

Whether China is preparing to intervene in Korea once again, preparing to manage the fallout of a US intervention in Korea, or just playing it safe, nobody knows.

Northeast China is already host to thousands of North Koreans refugees. Some are on the run from the repressive regime of Kim Jong-un, others are just seeking work, and still others are women forced into prostitution. If there is to be another conflict on the Korean Peninsula, China would be worried about a large number of Koreans fleeing across the border.

The second to last thing China wants is a new Korean war. But the last thing China wants is a united Korea under South Korean leadership. China's Communist Party leadership has learned the lessons of 1989-1991, when German reunification ultimately pushed the borders of NATO some 1000 kilometres to the east and Soviet communism was thrown into the dustbin of history.

If China does intervene in North Korea, it won't be to topple the Kim regime and promote peaceful reunification. It will be to prevent a collapse of the Kim regime in the face of domestic mismanagement and American pressure. Kim may go, but China will make sure that the regime remains. The long-term consequences of any such intervention are anyone's guess.

Salvatore Babones is a comparative sociologist at the University of Sydney. He is a specialist in global economic structure.

The views expressed in this article are the author's own and do not necessarily reflect Al Jazeera's editorial policy.