He was ruler of Kabul and Afghanistan (1826–39; 1843–63). Defeated in the first Anglo-Afghan War, he regained power in 1843 and consolidated his rule in Afghanistan through control of Kandahar (1855), northern Afghanistan (1850–59), and Herat (1863), so establishing the territorial outlines of modern Afghanistan.