The Second Anglo-Afghan War erupted in 1878, leading to Sher Ali to flee, and eventually die in February 1879. As Sher Ali's successor, Yaqub signed the Treaty of Gandamak with the British in May, relinquishing control of Afghanistan foreign affairs to the British Empire. An uprising against this agreement failed in October, and Yaqub abdicated. He was succeeded by Amir Abdur Rahman.
I would rather work as your servant, cut grass and tend your garden than be the ruler of Afghanistan. - Yaqub Khan, to a British viceroy in the 19th century''.