Diplomatic relations between Afghanistan and China were established in the 18th century, when Afghanistan was ruled by Ahmad Shah Durrani and China by Qianlong. Trade relations between these nations date back to at least the Han dynasty with the profitable Silk Road. China has an embassy in Kabul, and Afghanistan has an embassy in Beijing. The two countries share a border.

During the 20th century, China extended economic aid and multi-million dollar of loans to develop Afghanistan during the early Cold War period. This friendship was briefly interrupted after the Sino-Soviet split and the Soviet invasion of Afghanistan (1979), with the Soviet Union installing pro-Soviet and anti-Chinese regimes in Afghanistan. China supported the Mujahideen and was an important arms supplier to them. However, since the withdrawal of Soviet troops and détente of Soviet and subsequent Russian-Chinese relations, China-Afghan relations have also improved significantly in the 21st century.

During the NATO war in Afghanistan, Chinese political involvement initially was somewhat limited, but trade relations still continued with China as Afghanistan's largest trading partner and China giving Afghanistan millions of dollars in aid throughout the war. China's influence and shuttle diplomatic role in Afghanistan also grew over those years, China preparing to help broker peace in the war-torn country.

After the Taliban regained control of the country in 2021, China, like all other countries except the Russian Federation as of , does not formally recognize the reinstated Islamic Emirate but has transferred the embassy and accredited their ambassador. Despite its non-recognition, China negotiates issues of trade, investment, and aid with the Taliban government by referring to it as "Afghan Interim Government" ().

History Various Chinese dynasties have also occupied parts of Afghanistan and Central Asia around their current border; and Afghanistan has historically been at the center of the lucrative Silk Road.

Han dynasty The Han defeated the Dayuan in the Han-Dayuan war, thereby establishing Chinese control over parts of northern Afghanistan. Later the Han dynasty set up the Protectorate of the Western Regions to protect Silk Road trade through Central Asia. In antiquity, the region that is now Afghanistan was known for its devotion to Buddhism, which had been founded in India in the 5th century BC. Chinese records from the Han dynasty refer to Kabul as "Kao-fu", which is described as a wealthy cite located in the Hindu Kush mountains on a strategic location on the trade routes linking Central Asia to India. A Buddhist monk from what is now Afghanistan arrived in China in 2 BC and converted the first Chinese to Buddhism. Afghanistan was often visited by Chinese Buddhist pilgrims on their way to India in antiquity, and Buddhist sites such as Balkh and the Buddhas of Bamyan attracted many Chinese visitors. Chinese records credit craftsmen from Afghanistan with producing the first glass in China between 424 and 428 AD, through archaeological evidence suggests that glass was being produced earlier in China.

Tang dynasty In 605, emissaries from what is now Afghanistan arrived in Luoyang (at the time China's capital) to pay tribute to the Emperor in exchange for greater rights to trade with China. When the Tang dynasty was established in 618 AD, the claim to see Afghanistan as part of China's sphere of influence was inherited, a claim that successive Tang emperors were willing to enforce via military means.

During the Tang dynasty parts of Afghanistan were under the control of China's Protectorate General to Pacify the West. In 659, Soghd and Ferghana, along with cities like Tashkent, Samarkand, Balkh, Herat, and Kabul, became part of the protectorate under Emperor Gaozong. Afghanistan's Herat and Uzbekistan's Bukhara and Samarkand became part of the Tang protectorate. The Indian historian K. P. S. Menon wrote about the Chinese "performed the remarkable feat of sending an army of 100,000 men which marched up the Pamirs from Kashgar" and then crossed Afghanistan to occupy the Hunza Valley in what is now Pakistan under Tang General Gao Xianzhi.

The defeat of the Western Turks and the defeat of the Sassanids by the Arabs had facilitated the Chinese expansion under Emperor Gaozong into Herat, northeastern Iran and Afghanistan (Tukharistan), Bukhara, Samarkand, Tashkent, and Soghdiana, which previously belonged to the western Turks.

During the Tang dynasty, a period of prosperity and wealth that many Chinese see as one of the highlights of their history, trade flourished along the Silk Road between Afghanistan and China. The Chinese Buddhist monk Xuanzang passed through Afghanistan on his way to India and described with awe his wonder at viewing the Buddhas of Bamyan. Religions such as Nestorian Christianity first reached China in the Tang dynasty via Afghanistan, to be followed later by Islam.

The Church of the East Christians like the Bactrian Priest Yisi of Balkh helped the Tang dynasty general Guo Ziyi militarily crush the Sogdian-Turk led An Lushan rebellion, with Yisi personally acting as a military commander and Yisi and the Church of the East were rewarded by the Tang dynasty with titles and positions as described in the Xi'an Stele.

Mongol Empire Both regions were briefly unified under the Mongol Empire. This also contributed to the sustenance and growth of the Silk Road.

Silk Road Trade relations between Afghanistan and China mostly involved trade of fruit and tea via caravans through Xinjiang and the Wakhan Corridor on the border between the two countries. Buddhist monks from the area of what is now Afghanistan were involved in the Silk Road transmission of Buddhism to Han dynasty China. Faxian traveled to Afghanistan in the 5th century. In the 21st century, China and Afghanistan are making efforts to revive a New Silk Road through the Belt and Road Initiative.

Qing dynasty

Fazil Biy, the ruler of Kokand, and other Kyrgyz chieftains pleaded to Ahmad Shah Durrani to aid them against Qing expansionism. Ahmad Shah, delighted to use a casus belli in the name of Islam, accepted, sending men to occupy the regions between Tashkent and Kokand, though these men later withdrew by 1764 as any alliance failed to be forged.

In 1763, Ahmad Shah had dispatched an embassy to the Qing. His aims in this are unknown, however, an embassy allowed Ahmad Shah to establish himself as an emperor. The letter he sent to the Qing emperor Qianlong is missing, but from the Qing reply, the letter seems to have been dedicated to his recent conquests and victory at the third battle of Panipat, and Qing expansion.

The letter positioned Ahmad Shah's expansions as bringing order and stability to areas overrun with rebels and lawlessness (in reference to his campaigns in Iran and India). The battle of Panipat was strongly detailed in the letter, in what was likely a fath-nama, meaning a victory letter or declaration to celebrate ones victory. The Qing emperor ignored the effective threat and downplayed the Afghan victory.

In the second part of the letter, the Qianlong appeared much more defensive, in need of justifying the Qing conquest of the Dzungars and the Altishahr Khojas. He accused them of causing devastation and laying false accusations against him. A report also suggested that Ahmad Shah considered the territories the Qing claimed belonged to the Muslims. In reality, Ahmad Shah possibly wanted to establish spheres of influence, which was similarly done with the Ottomans which divided Iran between them, and a treaty with Bukhara that had established the Amu Darya as the border.

When the Afghan embassy had arrived in Beijing, the chief envoy, Khwaja Mirhan, had refused to kowtow before the Qing emperor. The Qing officials, in shock, demanded he kowtow, to which Mirhan acquiesced. This incident damaged the Qing-Afghan relations and Qianlong cut ties with the Afghans following this. No immediate consequence occurred, and the envoy was given favor.

Mirhan's refusal possibly came out of religious reasons, but the Qing received it as Ahmad Shah declaring himself equal to Qianlong. Qianlong, however, was reconciliatory and instead shifted blame on their escort. From Qianlong's view, he saw the Afghans as a significant power and attempted to impress the envoy and in contrast, Ahmad Shah, of the Qing empire. This was especially done in motivation of Altishahr's recent conquest and concerns over stability in the region.

Ahmad Shah's gifts included four horses, which were painted by the Qing court painter, Giuseppe Castiglione. Nonetheless, by the time of the envoy's return journey to Afghanistan, Qianlong made preparations to secure Qing territories.

In 1759, as the revolt of the Altishahr Khojas crumbled, two descendants of the Afaqi Sufi lineage crossed into Badakhshan, being pursued by the Qing forces. Fude, the Qing general of the expedition, demanded that Sultan Shah, the ruler of Badakhshan, to arrest the brothers. Sultan Shah accepted, likely wishing to have Qing military aid, especially against the Durrani Empire. Distrust occurred between the Qing and Sultan Shah due to the Afaqi descendants residing in Badakhshan for months, including Sultan Shah's possible initial refusal to hand them over, possibly intending to send them to Bukhara. Qianlong threatened invasion, which did not occur as one of the descendant's remains were sent to Yarkand.

The death of the Afaqi brothers spurned relations with the Afghans, causing Sultan Shah to plead to the Qing, claiming that Ahmad Shah intended to exact revenge for their deaths. No immediate Afghan invasion occurred. The Qing however, faced numerous frustrations with their tributaries in Central Asia, including a major revolt in Uch-Turfan that required tremendous effort to defeat.

As a result, Qianlong adopted a policy of strict non-interference, realizing that Qing troops in Altishahr were significantly stretched and spread thin. The Afghans, however, seen as a threat, would show the weakness of Qing control in the region.

In August 1768, Qianlong was informed of the Afghan invasion of Badakhshan led by Shah Wali Khan in May, with Afghan forces seizing Sultan Shah's capital, Fayzabad, who fled north. A Qing agent, Yunggui, held the position that the Qing should interfere in the conflict. Qianlong, however, affirmed that military intervention would be irrational, and strictly forbade any military interference. Historians see this as surprising, as the invasion by the Afghans threatened the Qing Empire itself.

Qing sources affirm that the Afghans established Sarimsaq, a child of the Afaqi's who escaped to Badakhshan, in Kunduz. Qianlong was distraught, as another possible revolt could revolve around Sarimsaq, with reports of Muslim travelers and funds being sent to Sarimsaq. This still did not convince Qianlong to act, and he refused to send any message negatively to Ahmad Shah at all. During this, Sultan Shah defeated the Afghan governor and reoccupied his capital, but feared another Afghan invasion, sending desperate letters to the Qing in the winter of 1768 to ask for help, claiming that Ahmad Shah would invade next year.

Qianlong harshly rebutted, blaming Sultan Shah for provoking the conflict with the Afghans and affirmed that he would only fight the Afghans if they actually invaded Qing territory. Sultan Shah wrote a letter to Emin Khoja in response in August 1769, expecting aid as he was a vassal, only to find himself totally abandoned. In December 1769, Sultan Shah wrote another letter which Qianlong received that accused him of failing to uphold his duties. Qianlong rebuked him, and stated that under no circumstances would the Qing aid him.