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

<P0-S0>  This was the second time British India invaded Afghanistan. <P0-S1>  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. <P0-S2>  Most of the British and Indian soldiers withdrew from Afghanistan. <P0-S3> 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. <P0-S4>  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. <SEP> <P1-S0>  Mohammad Yaqub Khan ceded various frontier areas to Britain while retaining full sovereignty over Afghanistan. <P1-S1> The Treaty of Gandamak officially ended the first phase of the Second Anglo-Afghan War. <SEP> <P2-S0> The Afghan Civil War fought between 1996 and 2001 was part of the wider War in Afghanistan ongoing since 1978. <P2-S1>  In 1996 the Taliban captured the Afghan capital Kabul and established the Islamic Emirate of Afghanistan. <P2-S2>  The Islamic State of Afghanistan government remained the internationally recognized government of Afghanistan. <P2-S3>  The Taliban's Emirate received recognition only from Saudi Arabia, Pakistan and the United Arab Emirates. <P2-S4>  The defense minister of the Islamic State of Afghanistan, Ahmad Shah Massoud, created the United Front (Northern Alliance) in opposition to the Taliban. <P2-S5>  The United Front included all Afghan ethnicities: Tajiks, Uzbeks, Hazaras, Turkmens, some Pashtuns and others. <P2-S6>  During the conflict, the Taliban received military support from Pakistan and financial support from Saudi Arabia. <P2-S7>  Pakistan militarily intervened in Afghanistan, deploying battalions and regiments of its Frontier Corps and Army against the United Front. <P2-S8>  Al Qaeda supported the Taliban with thousands of imported fighters from Pakistan, Arab countries, and Central Asia. <P2-S9> <ref name="Ahmed Rashid/The Telegraph"> </ref> <SEP> <P3-S0> Shagai Plateau, also referred to as Shagai Heights is an area of flat lands along the Khyber Pass. <P3-S1>  Fort Al Creator was nearby. <P3-S2>  The ascent to the Shagai Plateau begins near the entrance to the Khyber Pass from the southeast at Peshawar in what is now Pakistan. <P3-S3>  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. <P3-S4>  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. <P3-S5>  Fighting resumed in September 1879, after an anti-British uprising in Kabul, and finally concluded in September 1880 with the decisive Battle of Kandahar.