After months of chaos in Kabul, Mohammad Akbar secured local control, and in April 1843 his father, Dost Mohammad Khan, returned to the throne of Afghanistan. In the following decade, Dost Mohammad Khan concentrated his efforts on reconquering Mazar-e-Sharif, Kunduz, Badakhshan, and Kandahar. During the Second Anglo-Sikh War, in 1848-49, Dost Mohammad Khan's last effort to take Peshawar failed.
In 1854 the British were interested in resuming relations with Dost Mohammad Khan, whom they had more or less ignored since 1842. In the period immediately preceding the outbreak of the Crimean War, British officials in India, though they had no immediate concerns for Russian involvement, thought to make Afghanistan a barrier to Russian penetration across the Amu Darya. Dost Mohammad Khan agreed, apparently perceiving the utility of British backing against the Russians and even the Iranians, to whom the independent rulers of Herat always turned for support against re-absorption into the Afghan kingdom. In 1855 the Treaty of Peshawar reopened diplomatic relations, proclaimed respect for each sides' territorial integrity, and committed each to be the friends of each other's friends and the enemies of each other's enemies.
In October 1856 the Iranians siezed Herat, and the British, whose policy it was to maintain the independence of this city, declared war against Iran. After three months the Iranians withdrew from Herat and committed themselves never again to interfere there or elsewhere in Afghanistan. This brief war convinced the British that they should bolster the strength of Dost Mohammad Khan in an attempt to enable him to meet future challenges by the Iranians. In 1857 an addendum was signed to the 1855 treaty that permitted a British military mission to go to Kandahar (but not to Kabul) and to provide a subsidy during conflict with the Iranians. Fraser-Tytler notes that as Dost Mohammad Khan signed the document he proclaimed, "I have now made an alliance with the British Government and come what may I will keep it till death." Even during the 1857 Sepoy Rebellion in India, when British forces in the Punjab were thinned dramatically, Dost Mohammad Khan refused to take advantage of British vulnerability to retake the Pashtun areas under British control.
The British governor general of India at the time of the 1857 agreement with Afghanistan stated in a memorandum that the British would never again intervene in Afghan internal affairs or send an army across its borders unless Herat was besieged, and then only with Afghan consent. He went so far as to argue in favor of the Afghan absorption of Herat. In 1863 Dost Mohammad Khan retook Herat with British acquiescence. A few months later Dost Mohammad Khan died and, although his third son, Sher Ali Khan, was his proclaimed successor, he did not succeed in taking Kabul from his brother, Mohammad Afzal Khan (whose troops were led by his son, Abdur Rahman Khan) until 1868. Abdur Rahman Khan retreated across the Amu Darya and bided his time.
The disaster of the First Anglo-Afghan War continued to haunt the British for decades, and the 70 years following the defeat of 1842 were a period of extraordinary vacillation in British policy toward Afghanistan. Not only were political perspectives different in Delhi and London, but there were also changes in government between what writer John C. Griffiths calls "half-hearted Imperialists and ill-informed Liberals." The former favored what was called the Forward Policy, which held that the defense of India required pushing its frontiers to the natural barrier of the Hindu Kush so that Afghanistan (or at least parts of it, such as Herat) would be brought entirely under British control. The Liberal policy rested on the assumption that the Forward Policy was immoral and impractical. Many of its adherents believed that the Indus River formed the natural border of India and that Afghanistan should be maintained as a buffer state between the British and Russian empires. In the years immediately following the First Anglo-Afghan War, and especially after the 1857 Sepoy Rebellion in India, Liberal governments in London tended toward the buffer-state approach. By the time Sher Ali Khan had established control in Kabul in 1868, he found the British ready to provide arms and funds in support of his regime, but nothing more. Fraser-Tytler reports that Sher Ali Khan declared, "As long as I am alive, or as long as my governments exists, the foundation of friendship and goodwill between this and the powerful British Government will not be weakened." From this high point, relations between the Afghan ruler and the British steadily deteriorated over the next 10 years. Despite the good feeling between Sher Ali Khan and the British in 1869, the sensitivities engendered by the First Anglo-Afghan War made it impossible for Sher Ali Khan to accept a British envoy in Kabul, and there is no doubt that misperceptions colored the unfortunate sequence of events that led to the Second Anglo-Afghan War. In 1873 relations between Sher Ali Khan and the British viceroy began to become strained. The Afghan ruler was worried about the southern movement of Russia, which in 1873 had taken over the lands of the khan (ruler) of Khiva. Sher Ali Khan sent an envoy to ask the British for advice and support. In 1872, however, the British had signed an agreement with the Russians in which the latter agreed to respect the northern boundaries of Afghanistan and to view the territories of the Afghan amir as outside their sphere of influence. With this agreement in mind, and still following a noninterventionist policy as far as Afghanistan was concerned, the British refused to give any assurances to the disappointed Sher Ali Khan.
In 1874 Benjamin Disraeli became prime minister of Britain, and in 1876 a new viceroy was dispatched to Delhi with orders to reinstate the Forward Policy. Sher Ali Khan rejected a second British demand for a British mission in Kabul, arguing that if he agreed the Russians might demand the same right. The Afghan ruler had received intimidating letters from the Russians, but the British offered little in return for the concessions they demanded. Sher Ali Khan, still sensitive to the probable reaction in Afghanistan to the posting of British officers in Kabul or Herat, continued to refuse to permit such a mission.
After tension between Russia and Britain in Europe ended with the June 1878 Congress of Berlin, Russia turned its attention to Central Asia. In the summer of 1878 Russia sent an uninvited diplomatic mission to Kabul, setting in motion the train of events that led to the Second Anglo-Afghan War. Sher Ali Khan tried to keep the Russian mission out but failed. The Russian envoys arrived in Kabul on July 22, 1878, and on August 14 the British demanded that Sher Ali Khan accept a British mission. Sher Ali Khan had not responded by August 17 when his son and heir died, throwing the court into mourning.
When no reply was received, the British dispatched a small military force, which was refused permission to cross the Khyber Pass by Afghan authorities. The British presumably considered this an insult, but more likely it was viewed at the highest levels as a fine pretext for implementing the Forward Policy and taking over most of Afghanistan. The British delivered an ultimatum to Sher Ali Khan, demanding an explanation of his actions. The Afghan response was viewed by the British as unsatisfactory, and on November 21, 1878, British troops entered Afghanistan at three points. Sher Ali Khan, having turned in desperation to the Russians, received no assistance from them. Appointing his son, Yaqub, regent, Sher Ali Khan left to seek the assistance of the tsar. Advised by the Russians to abandon this effort and to return to his country, Sher Ali Khan returned to Mazare Sharif, where he died in February 1879.
With British forces occupying much of the country, Yaqub signed the Treaty of Gandamak in May 1879 to prevent British invasion of the rest of Afghanistan. According to this agreement and in return for an annual subsidy and loose assurance of assistance in case of foreign aggression, Yaqub agreed to British control of Afghan foreign affairs, British representatives in Kabul and other locations, extension of British control to the Khyber and Michni passes, and the cession of various frontier areas to the British.
An Afghan uprising against the British was, unlike that of the First Anglo-Afghan War, foiled in October 1879. Yaqub abdicated because, as Fraser-Tytler suggests, he did not wish to share the fate of Shuja following the first war.
Despite the success of the military venture, by March 1880 even the proponents of the Forward Policy were aware that defeating the Afghan tribes did not mean controlling them. Although British policymakers had briefly thought simply to dismember Afghanistan a few months earlier, they now feared they were heading for the same disasters that befell their predecessors at the time of the First Anglo-Afghan War. Fraser-Tytler summarizes the position of the viceroy:
He could hardly have based his policy on the assumption that after overrunning the country and thereby once more inflaming the hatred of every patriotic Afghan against us, we should by some magic discover among the Afghan chiefs a leader who would he acceptable both to ourselves and to the Afghan people . . . And yet this is what he did . . . The amazing thing is that while his assumption was wholly unwarranted his gamble was successful. While the British and Indian Governments were arguing over the dismembered corpse of the Afghan Kingdom, the one man who could fulfill the requirements o[ a desperately difficult situation was moving southwards into Afghanistan.
Just as the British interventionists were reaching this conclusion, the Liberal Party won an electoral victory in March 1880. This assured the end of the Forward Policy, which had been a major campaign issue.