With American and NATO troops having all but departed Afghanistan after 20 years of war, the country is still riven by internal conflict. 
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. 
Now at the end of the war, this is a look back at how it began, the complications that arose,and how it came to an ignominious end. 
The US involvement in Afghanistan intially began as an attempt to seek justice for the September 11 attacks.(Reuters: Sara K. Schwittek
September 11, the trigger
On October 7, 2001  less than a month after the September 11 attacks that killed about 3,000 people in the US then-president George W Bush launched Operation Enduring Freedom in Afghanistan.
The ruling Islamist Taliban had been sheltering Osama bin Laden and his Al Qaeda movement, which carried out the attacks in the US.
The operation opened a military front in the US “war on terrorism” and within weeks, US-led forces overthrew the Taliban, who had been in power since 1996.
A month later, about 1,300 American soldiers were on the ground, rising to almost 10,000 the next year.
Osama bin Laden managed to evade the US for a decade.(Reuters: Pentagon
How the Taliban rode it out
In 2003, US forces waded into another conflict, the Iraq War, to oust dictator Saddam Hussein. 
With US attention diverted, the fragmented Taliban and other Islamist groups regrouped in their strongholds in the south and east  from where they could easily travel between their bases in Pakistan’s tribal areas  and launched an insurgency.
In 2008, US command in Afghanistan called for more manpower and Mr Bush sent additional soldiers, bringing the total to 48,500 US troops deployed.
Two years later, Barack Obama had boosted the US presence there to about 100,000 troops, despite being elected president after a campaign that promised to end the Iraq and Afghanistan wars. 
The objective of the push was to crush the expanding Taliban insurgency and strengthen Afghan institutions.
The US had as many as 100,000 troops deployed in Afghanistan during the Obama administration’s “surge”.(AP: Massoud Hossaini
In 2011, the Obama administration achieved its goal of getting the 9/11 attack mastermind, bin Laden.
He was killed in a US special forces operation in Pakistan’s Abottabad. 
By the end of 2014, the NATO alliance had ended its combat mission, leaving only about 12,500 foreign troops in the country, about 10,000 of which were American. 
They remained with the intention of training up Afghan troops to take over the country, and to conduct anti-terrorist operations.
But the security situation in Afghanistan continued to deteriorate as the Taliban’s insurgency spread, with a branch of the Islamic State group also becoming active in South Asia in 2015.
Two years on, Donald Trump came to power and immediately scrapped the withdrawal plan, committing thousands more troops but Taliban attacks against Afghan soldiers in particular continued to multiply, prompting the US to step up airstrikes.
Donald Trump’s deal with the Taliban led to the final withdrawal of US troops.(AP: Alex Brandon
In 2018, with no let-up in the insurgency and the war becoming increasing unpopular domestically, the Trump administration opened discreet negotiations with the Taliban, offering to withdraw troops in exchange for Taliban promises not to let Afghanistan be used as a haven for jihadist groups like Al Qaeda.
By 2020, a historic deal between the two was signed, paving the way for a troop pullout by May 2021 in exchange for security guarantees from the Taliban and an agreement to hold peace talks with the Afghan government, which the Taliban has long labelled “illegitimate” and a stooge of Western powers.
The peace talks began in September but stalled after a wave of high-profile Taliban attacks against working Afghan women, activists and journalists.
Finishing off the Taliban insurgency proved to be too difficult a task for the US. (Reuters, file photo
By the time US President Joe Biden took office in 2021, troop numbers were down to 2,500, and Mr Biden promised to honour the withdrawal agreement, with the aim to pull troops out by September 11 a four-month delay from the previously agreed May pullout.
Violence at the hands of the Taliban had surged since the May deadline for withdrawal was delayed, with the group launching a blistering offensive that enabled it to take over rural districts near major cities, heightening fears that the Afghan security forces would be facing a rout.
Last week, US and NATO forces exited Bagram airbase the largest US military base in Afghanistan and command centre for anti-Taliban operations leaving America’s ability to provide air support for Afghan forces severely diminished.
As US troops left Bagram in disarray in the dead of night, Afghan commanders ran into coordination difficulties at the airbase in a troubling sign of what lies ahead.
Not America’s first rodeo in Afghanistan
In the 1980s, at the height of America’s Cold War with the Soviet Union, its Central Intelligence Agency (CIA) funnelled weapons and money to local rebels, the mujahedin, in the covert Operation Cyclone to defeat a Soviet invasion.
That first Afghan War set off 40 years of conflict in the country.
The CIA used Pakistan’s then-dictator Zia ul-Haq to funnel the funds, and Mr ul-Haq called upon Muslim countries to join the anti-Communist fight.
In a twist of irony, bin Laden was one of the men to volunteer.
Then-US president Ronald Reagan even invited the mujahedin for a meeting at the White House, praising them as freedom fighters against the Communist threat.
The Soviets finally left Afghanistan defeated in 1989, ending their 10-year occupation.
But after four years of infighting among the mujahedin that left about 50,000 Afghans dead, the Taliban rose from their depleted ranks in 1994. 
More than 39,000 Australian soldiers were sent to Afghanistan between 2001 and 2021.(Department of Defence: Corporal Ricky Fuller
What was Australia’s role?
Australia completed its troop withdrawal from Afghanistan last month, well ahead of the deadline for withdrawal of US troops in September.
Over 20 years, thousands of Australian troops were committed to support US troops and contain the threat of international terrorism.
Of the more than 39,000 Australian soldiers sent to Afghanistan since 2001, 41 were killed in what has been Australia’s longest war.
Australia’s military presence in Afghanistan has been marred by claims that special forces soldiers committed war crimes during their deployment.
A report by the Inspector-General of the Australian Defence Forces, Major General Paul Brereton, made a recommendation in November 2020 that 19 soldiers be investigated by the Australian Federal Police for the alleged murders of 39 prisoners and civilians.
Many Afghans, including ethnic Hazaras, are fearful of the future once international forces have left Afghanistan. (AP: Rahmat Gul
What if the Taliban retake Afghanistan?
Violence has been raging across Afghanistan since Mr Biden announced an unconditional troop withdrawal by September 11. 
‘We never want to go back’
Sodaba Herari is a prominent female journalist in Afghanistan. But she fears a US withdrawal could see female professionals like her lose more than just their jobs.
Read more
The peace talks between the Taliban and the Afghan government once a condition of withdrawal in Qatar are stuttering, with as many as a quarter of districts having fallen to the Taliban already.
With a Taliban takeover, Afghan women expect to lose many of the rights and freedoms they have enjoyed in recent years.
The Taliban, when they were last in power, forced women to wear headscarves, denied them education and prevented them from working.
The Taliban claims it has changed its views on women and female education, but many women are reluctant to believe that.
The Afghan government has resurrected militias mostly loyal to Kabul-allied warlords but with a history of brutal violence that has raised the spectre of civil war, similar to the fighting that devastated Kabul in the early 1990s.
The speed and ease of the Taliban’s effective takeover of an increasing number of districts now represent a massive psychological blow to the Afghan government.
On Monday, more than 1,000 Afghan troops fled into Tajikistan, forcing the neighbouring country to bolster the frontier with its own soldiers.
US troops abandon Afghan airbase in dead of night
The US military left Afghanistan’s Bagram Airfield after nearly 20 years by shutting off the electricity and slipping away in the night without notifying the base’s new Afghan commander.
Read more
Several hundred Afghan troops had already crossed into Tajikistan in recent weeks, in the face of an advancing Taliban. 
“We had to abandon our base because there was no coordination or interest among our commanders to counter the attack,” said Mohammad Musa, a soldier who had fled to Tajikistan after his base in Kunduz province fell to the Taliban last week. 
On Tuesday, Afghan authorities vowed to retake all the districts lost to the Taliban and deployed hundreds of commandos to counter the insurgents’ offensive in the north.
Mir Asadullah Kohistani, the Afghan commander now in charge of Bagram airbase, put on a brave face when asked about the Taliban’s rapid advances.
“We are trying to do the best and as much as possible to secure and serve all the people,” he said.