 With British forces occupying much of the country, Sher Ali's son and successor, Mohammad Yaqub Khan, signed the Treaty of Gandamak in May 1879 to prevent a British invasion of the rest of the country .
<clarity>  With British forces occupying much of the country, Sher Ali's son and successor, Mohammad Yaqub Khan, signed the Treaty of Gandamak in May 1879 to prevent a British invasion of the rest of the country .
 With British forces occupying much of the country, Sher Ali's son and successor, Mohammad Yaqub Khan, signed the Treaty of Gandamak in May 1879 in order to put a quick end to the conflict .