The Second Anglo-Afghan War (Pashto: د افغان-انګرېز دويمه جګړه) was a military conflict fought between the British Raj and the Emirate of Afghanistan from 1878 to 1880, when the latter was ruled by Sher Ali Khan of the Barakzai dynasty, the son of former Emir Dost Mohammad Khan.
This was the second time British India invaded Afghanistan. The war ended after the British emerged victorious against various Afghan forces, and the Afghans agreed to let the British attain all of their geopolitical objectives from the Treaty of Gandamak. Most of the British and Indian soldiers withdrew from Afghanistan. The Afghan tribes were permitted to maintain internal rule and local customs but they had to cede control of the area's foreign relations to the British, who, in turn, guaranteed the area's freedom from foreign military domination as a buffer between the British Raj and the Russian Empire.
After tension between Russia and Britain in Europe ended with the June 1878 Congress of Berlin, Russia turned its attention to Central Asia. That same summer, Russia sent an uninvited diplomatic mission to Kabul. Sher Ali Khan, the Amir of Afghanistan, tried unsuccessfully to keep them out. Russian envoys arrived in Kabul on 22 July 1878, and on 14 August, the British demanded that Sher Ali accept a British mission too.
The Amir not only refused to receive a British mission under Neville Bowles Chamberlain, but threatened to stop it if it were dispatched. Lord Lytton, the viceroy of India, ordered a diplomatic mission to set out for Kabul in September 1878 but the mission was turned back as it approached the eastern entrance of the Khyber Pass, triggering the Second Anglo–Afghan War.