Throughout the 19th century, the British Government was convinced that the extension of Russian influence over Central Asia constituted a real threat to its Indian domains. This had led Britain to first invade Afghanistan in 1839 with disastrous consequences.
In 1876, the spectre of Russian interference appeared once more when the Emir of Afghanistan, Sher Ali, was visited by a Russian diplomatic mission. When he then refused to accept a British envoy, the Viceroy of India, Lord Lytton, decided to act.
In September 1878, Lytton ordered a diplomatic mission to set out for Kabul, where he hoped to establish a political resident. This was a cost-effective way for British India to control the foreign relations of 'buffer' states. When the mission was turned back at the eastern end of the Khyber Pass, the British decided to replace Sher Ali.
In November 1878, three British columns, consisting of 40,000 men, invaded Afghanistan. One column marched through the Bolan Pass and seized Kandahar, a second occupied Ali Masjid fortress to secure the Khyber Pass before advancing to Jelalabad, while the third advanced along the Kurram Valley towards Kabul.
The third column, under Major-General Sir Frederick Roberts, found its way blocked at Peiwar Kotal by an Afghan force of 18,000 men and 11 guns. Roberts made a feint attack on the position, but led the 5th Gurkha Rifles and other troops in a night flanking movement that dislodged the Afghans. The British-Indian force inflicted heavy casualties and captured all the Afghan guns.
Sher Ali fled from Kabul, only to die of a heart attack soon after. He was succeeded as emir by his son, Yakub Khan, who signed the Treaty of Gandamak in May 1879. In return for British support, he accepted the presence of a British envoy, Major Sir Louis Cavagnari, and British control of Afghan foreign affairs.
Neither the new treaty nor the new emir was very popular in Afghanistan. In September 1879, mutinous Afghan soldiers from Herat appeared in Kabul demanding back-pay from the British. Cavagnari refused their request.
Accompanied by rioting Kabulis, the soldiers attacked and fired the British Residency, killing its 200 occupants, including Cavagnari. Yakub Khan did nothing to intervene.
When news reached India, Roberts was recalled from leave and put in command of a new force. Its mission was to reach Kabul and identify those responsible for the attack. Suspected rebels were to be tried and, if found guilty, executed. Yakub Khan was to be either defeated or deposed as occasion required.
Roberts' force was opposed by the Afghans at Charasiab, despite the fact that Yakub Khan had by then joined the British column. Roberts defeated the Afghan force and reached Kabul in October. Trials and executions began, but supporters of Yakub Khan and opponents of British occupation rose in revolt.
Several Afghan armies then marched on Kabul. The city had to be abandoned for the more defensible Sherpur Cantonment, situated to the north.
Just before Christmas, around 50,000 tribesmen attacked the 7,000-strong garrison. By dawn on Christmas Eve, the tribes had been dispersed. Roberts then re-occupied Kabul.
In May 1880, Roberts was joined by Lieutenant-General Sir Donald Stewart, who had advanced from Kandahar and defeated an Afghan army at Ahmed Khel.
In July, the vacant throne was offered to Abdur Rahman, a nephew of Sher Ali, who agreed to abide by the terms of the Treaty of Gandamak.
However, trouble was brewing in Herat, where another son of Sher Ali, Ayub Khan, launched his own bid to become emir. On 27 July 1880, a 1,000-strong British-Indian force sent to intercept him was overwhelmed by an army ten times its size at Maiwand. The survivors were pursued back into Kandahar, which was soon besieged by Ayub Khan’s victorious army.
In response, Roberts led a force out from Kabul to Kandahar. Despite the difficult terrain and oppressive heat, he covered over 500km (300 miles) in 20 days, hardly losing a man. On 1 September 1880, he defeated Ayub Khan outside Kandahar and ended the siege.
The British left Afghanistan in the hands of Abdur Rahman, who agreed to conduct his foreign policy through the Government of India. They also seized several Afghan districts in the Khyber and Kurram border areas. However, the provocative policy of maintaining a British resident in Kabul was quietly dropped. The last British and Indian soldiers left the country in April 1881.