The withdrawal of US troops from Afghanistan by September 11 will end America's longest war exactly two decades after the Al Qaeda terror attacks that triggered it.
In that time, more than 2,300 US military personnel lost their lives in Afghanistan, while more than 20,000 were wounded in action.
Afghan civilians have faced an even higher toll: a UN report last year estimated that 35,518 civilians were killed between 2001 and 2019.
The Pentagon says it has spent nearly $825 billion on operations in the country.
The war began with the US-led invasion on October 7, 2001, in pursuit of Al Qaeda's leadership who were being sheltered by the fundamentalist Taliban regime, which seized power in 1996.
Operation Enduring Freedom, launched by then-president George W Bush, opened a military front in the US War on Terror and toppled the Taliban within weeks.
By November 2001, there were about 1,000 American soldiers in Afghanistan, increasing to 10,000 the following year.
But attention was diverted from Afghanistan when the US invaded Iraq in 2003 to oust dictator Saddam Hussein.
The Taliban and other extremist groups were able to regroup in southern and eastern Afghanistan, from where they could easily travel to and from bases in Pakistan's tribal zones and wage an insurgency.
In 2008, Mr Bush sent more soldiers, raising their number to about 48,500, after the US command in Afghanistan called for more manpower.
Barack Obama, his successor, was elected to office that year on promises to end the wars in Iraq and Afghanistan. He boosted the size of the force to about 68,000 in 2009.
In December 2009, he sent in another 30,000 soldiers in an attempt to stem the growing Taliban insurgency and to support Afghan institutions.
By 2010, the US-led Nato force in Afghanistan numbered more than 150,000 soldiers, 100,000 of them American.
The Pentagon achieved a major success with the killing of Al Qaeda leader Osama bin Laden in an operation in Pakistan on May 2, 2011.
Three years later, the Nato alliance ended its combat mission in Afghanistan. However, 12,500 soldiers – including 9,800 Americans – were kept in the country to train Afghan troops and carry out anti-terrorist operations.
Security in the country soon degenerated as the Taliban's insurgency spread, with ISIS also active in 2015.
In August 2017, a new president, Donald Trump, scrapped timetables for a US pull-out and recommitted thousands more soldiers.
However, deadly attacks multiplied, especially against Afghan forces, and America dramatically increased its number of air strikes.
In 2018, Washington and Taliban representatives discreetly opened talks in Qatar, led by US special envoy Zalmay Khalilzad, focused on reducing the US military presence in Afghanistan.
In return, the US demanded that the Taliban prevent the country from being used as a safe haven for extremist groups, including Al Qaeda.
On February 29 last year, the US and the Taliban signed a deal that paved the way for the withdrawal of all foreign forces from Afghanistan by May this year. This would be in return for the insurgents offering some security guarantees and agreeing to hold peace talks with the Afghan government.
The peace talks began in Doha on September 12, but violence surged in Afghanistan as negotiations stalled and the Taliban resisted government calls for a ceasefire.
In the following months, a spate of high-profile assassinations, particularly in Kabul, was blamed on the Taliban, who denied involvement.
By the end of Mr Trump's presidency in January this year, US troop numbers were down to 2,500. In February, Nato had about 10,000 service members in the country.
The US withdrawal announced by President Joe Biden extends the pullout deadline by about five months, amid a growing consensus in Washington that little more can be achieved militarily in Afghanistan.