The United States descended on Afghanistan and its Taliban government in 2001 in the wake of the 9/11 attacks by Al-Qaeda, which had sought sanctuary in the country.

With American and NATO troops having all but departed Afghanistan after 20 years of war, here is a timeline of key events:

On October 7, 2001 -- less than a month after the September 11 attacks that killed around 3,000 people in the United States -- President George W. Bush launches "Operation Enduring Freedom" in Afghanistan.

The ruling Islamist Taliban had been sheltering Osama bin Laden and his Al-Qaeda movement, which carried out the 9/11 attacks.

The operation opens a military front in the US "war on terrorism" and within weeks, US-led forces overthrow the Taliban, who had been in power since 1996.

About 1,300 American soldiers are on the ground by November 2001, rising to almost 10,000 the next year.

American attention is diverted from Afghanistan when US forces invade Iraq in March 2003 to oust dictator Saddam Hussein.

The fragmented Taliban and other Islamist outfits regroup in their strongholds in southern and eastern Afghanistan, from where they can easily travel between their bases in Pakistan's tribal areas, and launch an insurgency.

In 2008, the US command in Afghanistan calls for more manpower. President Bush sends additional soldiers, bringing the total to 48,500 US troops deployed.

In 2009, Barack Obama -- elected president after a campaign that promised to end the Iraq and Afghanistan wars -- boosts the US presence to around 68,000. In December, he sends another 30,000 troops.

The objective is to stymie the growing Taliban insurgency and strengthen Afghan institutions.

By 2010, about 150,000 foreign soldiers are deployed in Afghanistan, of which 100,000 are American.

Osama bin Laden is killed on May 2, 2011 in a US special forces operation in Pakistan.

The NATO alliance ends its combat mission in Afghanistan in December 2014.

But around 12,500 foreign soldiers -- of which 9,800 are American -- remain to train Afghan troops and conduct anti-terrorist operations.

The United States descended on Afghanistan and its Taliban government in 2001 in the wake of the 9/11 attacks by Al-Qaeda
The United States descended on Afghanistan and its Taliban government in 2001 in the wake of the 9/11 attacks by Al-Qaeda AFP / MARTIN BUREAU

Security in Afghanistan deteriorates as the Taliban's insurgency spreads, with a branch of the Islamic State (IS) group also becoming active in South Asia in 2015.

President Donald Trump scraps any timetables for a US pullout and re-commits thousands more soldiers in August 2017.

However, deadly attacks multiply, especially against Afghan forces. The United States dramatically steps up air strikes.

The following year, Washington and Taliban representatives discreetly open talks in Doha, led by US special envoy Zalmay Khalilzad, focused on slashing the American military footprint in Afghanistan.

In return, Washington demands that the Taliban prevent the country from being used as a haven for jihadist groups including Al-Qaeda.

On February 29, 2020, the United States and the Taliban sign a historic deal.

It paves the way for the withdrawal of all foreign forces from Afghanistan by May 2021 -- in return for the insurgents offering some security guarantees and agreeing to hold peace talks with the Afghan government.

The peace talks begin on September 12 but violence surges in Afghanistan and negotiations between the Taliban and Afghan government stall.

The Taliban are blamed for a wave of targeted killings against high-profile activists, politicians, journalists and working women.

Troop numbers by the end of Trump's presidency in January 2021 fall to 2,500 as support for military action wanes. As of February, NATO has around 10,000 service members in the country, the largest contingent of which is from the United States.

President Joe Biden announces he will stick to the agreement with the Taliban, but delays the drawdown deadline until September 11.

Violence surges after the missed May 1 deadline and the Taliban launch a blistering offensive, capturing a number of rural districts close to major cities, stirring fears that Afghan security forces will buckle once US and international troops leave.

Officials on June 2 announce the departure of all US and NATO troops from Bagram, Afghanistan's biggest air base, signalling that the complete withdrawal of foreign forces is imminent.

Bagram served as the linchpin for US-led operations in Afghanistan, and the ability of Afghan forces to hold the base is likely to prove pivotal to maintaining security in nearby Kabul and keeping up pressure on the militants.

The Taliban welcome the latest step in the pullout of foreign troops.