Afghanistan is not known as the graveyard of empires for nothing. Alexander the Great, the British empire, the Soviet Union and now mighty America, all have been humbled in their attempts to conquer this fierce country. Now China, the world’s nascent superpower, risks falling into the same trap before it has even properly begun its own neo-imperial project.

As America’s longest war draws to a close before the symbolic date of September 11 2021, China’s leaders and foreign policy thinkers are struggling with contradictory impulses. On the one hand, Beijing has always felt the US campaigns in Afghanistan were part of a new “Great Game” intended to encircle, contain and potentially destabilise China, which shares a small strip of border with the country. So America’s final humiliating withdrawal and potential re-establishment of Taliban control in the country is welcomed from that perspective.

On the other hand, the looming power vacuum has the potential to create chaos in a country that could destabilise the entire region. A renewed civil war could attract jihadist forces that are already turning their attention to what several western governments have described as the “genocide” of China’s Muslim Uyghur population just across the border. Beijing is especially worried about Uyghur fighters returning from Syria, where a small number have fought alongside Isis.

Early this month, foreign ministers from China, Afghanistan and Pakistan met to discuss security arrangements following the US pullout from the country. China has also courted the Taliban and has even held out the offer of infrastructure and rebuilding projects to the group. Beijing is hoping to extend its grand Belt and Road infrastructure construction project from its main branch in Pakistan up into Afghanistan and is optimistic this can help provide stability to the war-torn country.

Having witnessed and welcomed America’s overextension in its “forever wars” of the last two decades and with memories of the Soviet experience in Afghanistan in the 1980s, the last thing China’s leaders want is to become bogged down in their own Afghan quagmire. Beijing considers the US entanglements in Afghanistan and Iraq after the 9/11 terrorist attacks mostly as a foreign policy distraction that provided a window of opportunity for a more assertive China.

Now the White House has publicly said it is ending the war in part to free up resources to meet the challenge of this rising power. The expectation that Beijing will get sucked into the country may well have played a part in President Biden’s decision to leave.

Beijing’s plan to extend the Belt and Road into Afghanistan is fraught with danger. In most other countries, these projects have been carried out with Chinese loans paying for Chinese workers to build roads, railways, ports and bridges. But thanks in part to the treatment of Uyghurs in Xinjiang, Chinese contractors have already been targeted in parts of Pakistan. Given the much greater danger in Afghanistan and the political cost for Xi Jinping if workers come home in body bags, it is likely that any Belt and Road project in the country would have to be accompanied by a significant security presence.

Advisers to the Chinese Communist party have already recommended that China send peacekeeping troops to the country under the auspices of the United Nations to protect the “safety and interests” of Chinese people and companies there. Such missions have a habit of spiralling into much deeper engagement. President Xi should heed the lessons of history and avoid the fate of other would-be empires.