The Afghanistan War was a two decades-long war in Afghanistan which began with the United States-led invasion of Afghanistan and overthrow of the Islamic Emirate of Afghanistan regime in 2001 and ended with the overthrow of the pro-American Islamic Republic of Afghanistan government by the Taliban insurgents in 2021. The goal of the initial US invasion was to destroy the al-Qaeda terrorist group's training camps in the country and to overthrow the extremist Taliban regime, which had given sanctuary and protection to the terrorists, and the USA was assisted in the invasion by a coalition of Western countries which included the United Kingdom, Australia, Germany, and Canada. The American involvement in the invasion did not require a large ground force, however, as they were allied to the anti-Taliban Northern Alliance of Tajiks, Uzbeks, Hazaras, and moderate Pashtuns; the Green Berets helped the Northern Alliance take control of the country as the US Air Force launched bombing raids on Afghanistan from nearby Central Asian countries. By December 2001, Kabul, Kandahar, and the other major cities were in Northern Alliance hands, and the al-Qaeda training camps were destroyed and their forces decimated. The local tribes agreed upon Hamid Karzai as the new leader of Afghanistan, and he would be elected president in 2004 with American support.
Karzai's Afghanistan became an Islamic republic sympathetic to the West, but the government proved to be corrupt and ineffective, and neither the Taliban nor al-Qaeda were defeated. Instead, al-Qaeda's leadership and fighters fled to the Pakistani border regions, and the Taliban launched a 2002 offensive funded by the opium harvest. The United Nations formed the International Security Assistance Force (ISAF) coalition to assist in the maintenance of security during the occupation of Afghanistan, and the coalition forces worked together with the Afghan National Army and Afghan National Police to conduct counter-insurgency operations. The ISAF forces faced increased opposition as more US forces headed to fight in the simultaneous Iraq War against other Islamist militants, and the ISAF forces began to withdraw after 2008. In 2014, the last major US forces left the country, leaving behind only a handful of advisers. The Taliban insurgency became very successful as they faced the inexperienced ANA soldiers without their US allies, and they occupied large pockets of the country, as did the Islamic State terrorist group. The NATO phase of the war is often said to have ended on 28 December 2014 with the US withdrawal, but the Taliban insurgency continued. The Islamic State became a threat as many Taliban commanders and foreign fighters pledged their allegiance to the self-proclaimed Caliph Abu Bakr al-Baghdadi, and the Islamic State committed brazen acts of terror against civilians. The Taliban would continue its terror campaign, but a more moderate leadership under Haibatullah Akhunzada announced that they would not target random civilians, instead targeting Afghan and foreign soldiers. As of May 2017, over 13,000 foreign troops remained in Afghanistan without any formal plans to withdraw. In late 2020, peace talks between the Afghan government and the Taliban resumed; in August, the Afghan government agreed to release several Taliban prisoners as Taliban representatives met with the Afghan and Pakistani governments on Pakistani soil. In early 2021, the new President of the United States, Joe Biden, announced that he planned for US forces to completely withdraw from Afghanistan by 11 September 2001, the twentieth anniversary of the 9/11 attacks. As the last international troops withdrew from Afghanistan in the summer of 2021, the Taliban launched a major offensive against the Afghan government forces, achieving unexpected success in the north, coming to control 100 of Afghanistan's 350 districts by early July 2021, and threatening to recapture their founding location of Kandahar. Meanwhile, the Americans continued to withdraw their ground forces and, perhaps more crucially, their air support from Afghanistan, hurriedly evacuating Bagram Airbase on 2 July. The Afghan military's strategic withdrawals from several districts demoralized its soldiers and created a culture of defeatism; over 1,000 Afghan troops even fled across the border with Tajikistan rather than fight back against the Taliban offensive in Badakhshan Province. In response, over 30,000 Afghan civilians took up arms and formed volunteer militias in a desperate bid to prevent the Taliban from overrunning the country in a manner which former deputy UN envoy Peter Galbraith feared would recall memories of the Fall of Mosul to ISIL in June 2014, when the Iraqi Army collapsed in the face of an insurgent blitz. On 5 July, the Afghan government initiated a counterattack against the Taliban in the north, intending on reversing their gains and preventing them from obtaining the upper hand in the concurrent peace talks in Doha, Qatar. However, the Afghan National Army continued to suffer from demoralization and mass desertions as the Taliban continued to capture Afghanistan's border crossings, and, in the first two weeks of August, a series of provincial capitals, including the former Northern Alliance strongholds of Samangan and Fayzabad and the major city of Kunduz. By 11 August 2021, the United States intelligence community predicted that Kabul would fall within 1-3 months. The Taliban's momentum only increased, however, as more provincial capitals fell with light or no resistance in a span of a week, and, on 15 August 2021, the Taliban entered the encircled capital of Kabul itself, forcing President Ghani to flee the country. From exile, Ghani relinquished power, and the Taliban declared the war over while forming an interim government in preparation for the restoration of the Islamic Emirate.