The Second Anglo-Afghan War 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. The war was part of the Great Game between the British and Russian empires.
The war was split into two campaigns - the first began in November 1878 with the British invasion of Afghanistan. The British were quickly victorious and forced the Amir - Sher Ali Khan to flee. Ali's successor Mohammad Yaqub Khan immediately sued for peace and the Treaty of Gandamak was then signed on 26 May 1879. The British sent an envoy and mission led by Sir Louis Cavagnari to Kabul but on 3 September this mission was massacred and the conflict was reignited by Ayub Khan which led to the abdication of Yaqub.
The second campaign ended in September 1880 when the British decisively defeated Ayub Khan outside Kandahar. A new Amir - Abdur Rahman Khan selected by the British, ratified and confirmed the Gandamak treaty once more.