In 1838 they occupied Afghanistan. Officially, their aim was to reinstall the recently deposed Emir Shah Shuja on the Afghan throne, but after that had been achieved, in 1839, they maintained their occupation to support his puppet government – ultimately as a means of moving towards British rule – until they were forced to withdraw by tribal rebellions and disastrous military reverses in 1842.