The modern state of Afghanistan began with the Hotak and Durrani dynasties in the 18th century. In the late 19th century, Afghanistan became a buffer state in the "Great Game" between British India and the Russian Empire. Following the Third Anglo-Afghan War in 1919, the country became free of foreign dominance, eventually becoming the Kingdom of Afghanistan in June 1926 under King Amanullah. This kingdom lasted almost fifty years, until King Zahir was overthrown and a republic was established in July 1973. In 1978, after a second coup, Afghanistan became a socialist state, provoking the Soviet–Afghan War in the 1980s against mujahideen rebels. By 1996 most of Afghanistan was captured by the Islamic fundamentalist group, the Taliban, who ruled most of the country as a totalitarian regime for over five years. The Taliban were removed from power after the US invasion in 2001 but still controlled a significant portion of the country. The twenty-year-long war between the government and the Taliban reached a climax with the 2021 Taliban offensive and the resulting fall of Kabul which returned the Taliban to power.