In the early decades of the 19th century, Afghanistan served as a buffer zone between British interests in South Asia and Russians in Central. Both those and others also worried about the influence of the rebels on their empire. In the end, Afghanistan gained partial independence.
The situation on the eve of the conflict
Dost Mohammad became the emir of Afghanistan in 1834 when Great Britain and Russia tried to gain control of Central Asia. At this time, the Afghan rulers were able to maintain partial independence, although some compromises were taken into account.
In 1838, the British defeated the Sikhs and captured the Punjab and Peshawar valleys in what is now Pakistan. From there, they began operations in the Hindu Kush and in the Pamirs, in order to partially undermine Russia's influence in the area. The British wanted to make Afghanistan a buffer state to protect British India from expansion. The Afghan wars of 1839-1842, 1878-1880 and 1919 were caused by British fears about the further expansion of Russia.
Causes
The first Anglo-Afghan war (1838-1842) was fought between the British Indian army in alliance with the still independent Sikhs under the leadership of Ranjit Singh and the rulers of Kabul and Kandahar from the Barakzai dynasty. Its purpose was the overthrow of Dost Mohammad Khan and the restoration of the former ruler of the Sadozai Shuja Shah family. The current ruler dealt with Persia and Russia, while the British could trust Shah Shuju. At stake was the food market in Central Asia. Russia sought to seize Khiva in the hope that it would become the center of all trade and undermine the commercial superiority of those who dominated the sea.

Since 1829, the British considered it necessary to extend their influence to Central Asia before the arrival of the Russians. To protect their interests, they sent envoy Alexander Burns through Sindh to Lahore in 1830 and through Kabul to Bukhara in 1831-32. At this time, Russia's strong influence in Persia was used to encourage the Persian campaign against the strategically important Herat fortress, which was ruled by Sadozai. The British sought to save Herat from Persia and, thus, to keep the Russians in the west.
Meanwhile, the situation was such that the British could not simultaneously be friends with Ranjit Singh, the ruler of the Punjab, and Dost Mohammadomkhan, because they were in a state of hostility. Even Burns, having been in Kabul, could not reconcile the two leaders.
Start
In 1838, Governor-General Lord Auckland signed the Simla manifesto, which actually became a declaration of the Anglo-Afghan war on the rulers of Barakzai in Kabul and Kandahar. The Sikhs played a minimal role in subsequent military operations. The Indian army assembled by the British entered Afghanistan in the spring of 1839 and made its way through Kandahar and Ghazni to Kabul. Shah Shuja was restored as ruler, but he was not accepted. Barakzai and their followers began the struggle.
The invading troops occupied the territory, but complacency after an obvious victory, combined with the need to engage in the economy, weakened the occupying forces. In November 1841, an uprising took place in Kabul. Burns, like many others, was killed. Although Dost Mohammad was held captive and was in India, his son Akbar was not going to allow the British under the command of McNakten to negotiate. The commander was killed, and only a small part of the Kabul garrison survived the transition to Jalalabad. Those who were not killed by the Afghans froze in the snow along the way.
Shah Shuji was ultimately destroyed too. The change of governor-general in India, coinciding with the change in government in London, led to the dispatch of the “retaliation army” to Afghanistan in 1842. After completing the mission, the army returned to India, taking Akbar hostage, leaving the Afghans themselves to create a government among anarchy, which is the result of their crimes, as stated by the Governor-General of India Ellenborough in Simla on October 1, 1842.
Dost Mohammad returned to the capital in 1843.
The Second Anglo-Afghan War (1878-1880)
The aim of the British was to impose a military presence in Afghanistan and keep the Russians away from India. After six years of quarreling between the sons of Dost Mohammad, Shir Ali became an emir in 1869. Four years later, he was on good terms with the British in India, being confident that he could count on their friendship and support. The viceroy (Lord Mayo) gave him two batteries of artillery and several thousand pieces of weapons. In September 1873, Shir Ali asked Mayo's successor, Northbrook, what Britain would do if Russia, its new neighbor in the north, attacked Afghanistan. According to instructions from London, Northbrook refused to give a direct answer. The emir was disappointed, as he wanted help without interfering in his internal affairs.
The British government, meanwhile, began to worry about news of Russia's recent successes among the khanates and the outbreak of war between Russia and Turkey in 1877.
When the Disraeli government sent troops to Malta as a warning to the Russians and then fought with Turkey, the military department in St. Petersburg sent a mission to Kabul and three columns of troops to the Afghan border, the Russian Foreign Ministry later denied information about these movements.
Knowing that the Berlin Treaty has already been signed, the Russian military mission arrived in Afghanistan and settled in Kabul. Soon, the British there appeared a similar one. Shir Ali, who supported Russia, refused to accept it. An ultimatum was sent to him, to which he did not answer. On November 21, 1878, General Roberts raised three troops, thereby starting a new Anglo-Afghan war.
A few months later, Shir Ali was defeated, and power passed to his son Yakub. The Russians in whom he believed did not try to help him. In the Gandamak Treaty (May 1879), Yakub Khan recognized British control over his foreign relations, agreed to receive a permanent envoy in Kabul, allowed British troops to control the main passages to Afghanistan from the south and received an annual subsidy of 60,000 rupees.
Jacob received the English envoy, Sir Louis Cavagnari, but did nothing to stop the murder of himself and his staff in September 1879. Roberts again led his troops and within six weeks after that Kabul was occupied and Yakub was overthrown.
For ten years, Abdur Rahman, the grandson of Dost Mohammad, lived in exile in Samarkand. Now they called on him to return to Afghanistan and take the place of Yakub. He did this in January 1880 and was immediately met by the British.
In April, Gladstone became prime minister, and in July, the British officially recognized Abdur Rahman as ruler of Afghanistan. Meanwhile, Roberts and his troops were confronting Afghan forces in the west. Ayyub Khan, the son of Shir Ali and a cousin of Abdur Rahman, commanded the troops, which in July dealt a heavy blow to one British unit at Maiwand. After his famous forced march from Kabul to Kandahar, Roberts defeated Ayub Khan.
Until the spring of 1881, the last British Indian troops were withdrawn. Abdur Rahman recognized the British leadership with his external relations and military presence at the passes. In return, Great Britain promised him a subsidy and assistance in confronting any unprovoked aggression.
Third Anglo-Afghan War (1919)
It was not announced, lasted from May 4 to June 3 and led to the complete independence of Afghanistan. Emir Amanullah (1919-29) took the throne on February 25 after the assassination of Emir Khabibullah and the five-day rule of Nasrullah Khan. An ardent nationalist who resented the hegemony of Great Britain over Afghanistan, Emir Amanullah immediately declared independence.
The fighting of this Anglo-Afghan war began on May 4, 1919, when Afghan troops cut off Lundy-Kotal's water supply on the Indian side of the border, and Britain responded by closing the Khyber Pass. The British forces had some successes, but they were neutralized when General Nadir Khan opened a new front in the southeast and attacked the British base at Thale.
On May 24, the British bombed Kabul, which provoked a response from Amanullah. On June 3, 1919, a pact was concluded. Peace between Afghanistan and Great Britain was finally restored after a series of negotiations in Rawalpindi (August 8, 1919), Mussouri (July 18, 1920) and Kabul (December 2, 1921).