Question: What officially ended the first phase of the military conflict between the British Raj and the Emirate of Afghanistan from 1878 to 1880?

The Afghan Civil War fought between 1996 and 2001 was part of the wider War in Afghanistan ongoing since 1978.  In 1996 the Taliban captured the Afghan capital Kabul and established the Islamic Emirate of Afghanistan.  The Islamic State of Afghanistan government remained the internationally recognized government of Afghanistan.  The Taliban's Emirate received recognition only from Saudi Arabia, Pakistan and the United Arab Emirates.  The defense minister of the Islamic State of Afghanistan, Ahmad Shah Massoud, created the United Front (Northern Alliance) in opposition to the Taliban.  The United Front included all Afghan ethnicities: Tajiks, Uzbeks, Hazaras, Turkmens, some Pashtuns and others.  During the conflict, the Taliban received military support from Pakistan and financial support from Saudi Arabia.  Pakistan militarily intervened in Afghanistan, deploying battalions and regiments of its Frontier Corps and Army against the United Front.  Al Qaeda supported the Taliban with thousands of imported fighters from Pakistan, Arab countries, and Central Asia. <ref name="Ahmed Rashid/The Telegraph"> </ref> <SEP> Shagai Plateau, also referred to as Shagai Heights is an area of flat lands along the Khyber Pass.  Fort Al Creator was nearby.  The ascent to the Shagai Plateau begins near the entrance to the Khyber Pass from the southeast at Peshawar in what is now Pakistan.  It was the site of a British encampment during the Second Anglo-Afghan War which began in November 1878 when Great Britain, fearful of what it saw as growing Russian influence in Afghanistan, invaded the country from British India.  The first phase of the war ended in May 1879 with the Treaty of Gandamak, which permitted the Afghans to maintain internal sovereignty but forced them to cede control over their foreign policy to the British.  Fighting resumed in September 1879, after an anti-British uprising in Kabul, and finally concluded in September 1880 with the decisive Battle of Kandahar. <SEP> The Treaty of Gandamak officially ended the first phase of the Second Anglo-Afghan War.  Mohammad Yaqub Khan ceded various frontier areas to Britain while retaining full sovereignty over Afghanistan. <SEP>  This was the second time British India invaded Afghanistan.  The war ended after the British emerged victorious against the Afghan rebels 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. 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.