By Emily Clark and Lucia Stein
When the Taliban made its way into Afghanistan's capital on Sunday, their decades-long war to return to power was won.
Despite being outnumbered by Afghan troops - soldiers who had been trained by the world's strongest military organisation - the militants were able to march into Kabul and claim their prize.
Taliban members poured into the abandoned palace, taking a seat behind the presidential desk, while panic gripped the city and the world was left reeling over the speed of the advance.
Only nine days ago, United States intelligence said Kabul could fall in three months. Even then, the analysis came with the disclaimer that it wasn't a 'foregone conclusion' Afghan forces would lose control of the capital.
The proof of that miscalculation was soon evident as the government collapsed, the president having fled the country to "avoid bloodshed".
Kabul's last stand may have been short, but the Taliban has been playing a very long game.
The group has had one objective: to establish an Islamic emirate of Afghanistan. That was their goal in 1996, it was their goal last Thursday and it's their accomplishment today.
Yet, one of the big questions many are left asking is: how exactly did we get here?
According to several analysts, the answer lies somewhere between the Taliban's refusal to accept any other outcome and America's desperation to get out of Afghanistan.
The 'smoke and mirrors' peace deal
Like the rest of the world, the Taliban was watching Donald Trump's America and ultimately what they saw was an opportunity, according to counter-terrorism expert Professor Greg Barton.
"When Donald Trump signed a peace agreement with the Taliban back in February last year … they [the US] were sucked in by a smoke and mirrors trick," he told the ABC.
Barton likened the Taliban's participation in the peace deal to magicians' craft.
"You're so busy looking at what they're doing with their left hand, you don't see what they're doing with their right," he said.
"This whole peace treaty, largely conducted in Doha, was a deliberate distraction designed to lower the guard and to see what they could get out of Trump's America."
The Taliban knew America wanted out, and fast.
What they got was an "audacious" deal that included the release of 5000 Taliban prisoners.
Crucially, the Afghan government and leader Ashraf Ghani were largely excluded from the peace deal process.
"The deal signalled to regional actors that they needed to hedge their bets and start making provisions for the end of the Ghani regime in Afghanistan," global security and strategy expert Dr Benjamin Jensen wrote for the Atlantic Council.
The stage was set.
After President Joe Biden took office, the date for US troop withdrawal was pushed back to 11 September.
While there was something symbolic about ending the war in Afghanistan on the 20th anniversary of the event that started it, the move may have emboldened America's enemy.
"It's really foolish to make an association between an American withdrawal and … the 9/11 attacks because al Qaeda and the Taliban … seized on it and said 'this is proof that we are right, God has blessed us and we are prevailing. Our cause is just'," Barton said.
"Trump had played into their hands in signing the peace treaty. Biden repeated that mistake."
The Taliban got ready, and with their replenished membership they laid the groundwork to launch an offensive as the Americans retreated.
The movements from May
With the US committed to a hard deadline, the Taliban seized their opportunity in May.
Their assault was driven by a deliberate military strategy and "a psychological warfare campaign".
The Afghan troops "were outmaneuvered by a more adaptive military organisation", Jensen wrote.
"The shadowy insurgent network deft at executing rural ambushes and planting improvised explosive devices has been replaced by a complex organisation managing as many as 80,000 fighters who are even more skilled at using social media than AK-47s," he wrote.
The Taliban conquered vast swathes of territory in rural Afghanistan before swiftly moving onto larger cities.
By 6 August they had taken over the capital of Nimruz province in the south, the first provincial capital to fall since they ramped up their attacks.
In just 10 days they swept across Afghanistan, capturing strategic posts, freeing prisoners and forcing hundreds to flee before arriving at the gates of Kabul on 15 August.
"What the Taliban intended to do was take all these districts when the American military was almost completely drawn down, surge ahead and then take city after city, provincial capital after provincial capital," Barton said.
"It wasn't an accident. It wasn't something made up on the run. This was something they'd planned for, worked out."
While smaller than the Afghan army, experts say the militants deliberately targeted main highways and transport centres, trapping Afghan forces and cutting off access to supplies.
One of their other strategies was negotiated surrenders. Associate Professor Marianne Hanson from the school of Political Science and International Studies at the University of Queensland said they would try to negotiate with community elders "for the people to surrender and their lives would be spared".
Those negotiations sometimes resulted in government forces being removed from the battlefield without a single shot fired, the New York Times reported.
Through this process, the Taliban secured more weapons, ammunition and vehicles as well as victories to use as part of their propaganda material.
It was a strategy which proved "really, really effective", according to Dr Natasha Lindstaedt, an expert on authoritarian regimes and failed states.
As the Taliban took provincial capitals, they crafted text messages and Twitter posts that targeted the soldiers protecting other cities.
"Put yourself in the shoes of an Afghan soldier: You are in a combat outpost, running out of food and ammunition, fighting for an unpopular government, and forced to pay bribes due to endemic corruption. As you look at your cell phone, all you see are images of fellow soldiers surrendering. Even if you opt to fight, your morale and will to fight have been undermined," Jensen wrote.
Morale among Afghan forces was collapsing and the Taliban's messaging and strategy to stoke resentment at the government was paying off, according to Lindstaedt.
The Afghan forces
As Biden sought to provide a response to the fall of Kabul this week, he claimed: "The Afghan military collapsed. Sometimes without trying to fight."
But Barton said the combination of the Taliban's strategy and the lack of air support really did not give them much of a fighting chance.
He said air support was an instrumental part of the Afghan military's strategy.
When the US left Bagram airbase on 2 July in the middle of the night, they took with them 18,000 civilian contractors who "are a key element to how the American military works," Barton said.
"They replicated an American-style military system in Afghanistan, but then they took away the basic components that made it work.
"Those civilian contractors kept the Afghan military flying, and in a mountainous country where the Taliban control the highways, those aircraft - helicopters and transport aircraft - are vital.
"So suddenly, the Afghan military had no means of relying on air support."
The lack of air support eroded confidence in the Afghan military ranks. There were supply problems so soldiers didn't have enough food to eat, fuel for their vehicles or bullets for their guns.
"Many of them hadn't been paid for months and the Taliban had been working out negotiations with senior regional leaders to surrender, rather than face military defeat and loss of life," Barton said.
"It's hardly surprising that those soldiers, by and large, didn't fight back."
For 20 years, Afghans fought alongside Americans and NATO forces to oppose the Taliban, becoming dependent on US funding and military support.
America had spent approximately US$145 billion (NZ$212 billion) trying to rebuild Afghanistan, and of that about $83 billion went to developing and sustaining its army and police forces, according to the Office of the Special Inspector General for Afghanistan Reconstruction.
But analysts suggest the Afghan army was not just dependent on resources, but also on the US presence for their will to fight. Without it, morale plunged and the country descended into chaos.
Lindstaedt said when the US left, "confidence eroded".
"It was like a snowball effect, as with each provincial capital that the Taliban was able to take, the more confidence it gained," she said.
A single political objective
The Taliban may be a different outfit to 20 years ago, but ultimately their objective has not changed.
"The people who became the Taliban, and for the past 20 years the Taliban, had this clear vision," Barton said.
"What they want to do is establish the Islamic emirate of Afghanistan where there are no foreign troops and where Afghanistan is ruled by Afghans following, according to them, the true vision of Islam."
While the US has seen four presidents, all with different approaches and, as some analysts have argued, no overarching strategy, the Taliban has continued to move toward their objective.
Biden was determined the war would not extend into a fifth presidency, but in doing so former US secretary of state Condoleezza Rice said he did not leave Afghanistan with enough capacity to hold the country without America's support.
Two decades was not enough to complete a journey "from the 7th-century rule of the Taliban and a 30-year civil war to a stable government," Rice wrote in an opinion piece published in the Washington Post.
Her point: that Afghans did not choose the Taliban, that they fought and died alongside Americans. And they needed more time.
And perhaps the West did too.
This week, Biden said the US had achieved its mission to seek revenge for 11 September and "make sure al Qaeda could not use Afghanistan as a base from which to attack us again".
"We did that," he said.
As part of the peace deal, the Taliban agreed the "soil of Afghanistan" would not be used by al Qaeda, or any other group or individual to "threaten the security of the US or its allies".
"They're willing to appear rational, pragmatic and willing to engage with the international community at certain moments, but they've never made [good] on any promise that they made, not once," Lindstaedt said.
Analysts are now predicting Afghanistan will again become a terrorist training ground, with foreign fighters allowed to stream across the borders and into al Qaeda camps.
Barton estimates there are already 600 al Qaeda members operating in Afghanistan today.
Meanwhile, the US and its allies are scrambling to evacuate their people, and the Taliban's long-held vision of an Afghanistan free of foreign Western troops is realised.
Those left behind
Those left to face the realities of this moment are of course the Afghan people.
Fear and anxiety drove many to Kabul's airport earlier this week, desperately hoping to escape the Taliban's rule.
Others have reportedly lined up at cash machines to withdraw their life savings, fearing what will happen during the turbulent period ahead.
Among Americans, the sentiment is that it was time to leave and Biden was politically invested in that, but exactly how he led the withdrawal has been questioned.
"It's not that Biden was necessarily wrong to go ahead with withdrawal because that was a legitimate choice, but it was the way he failed to manage the transition and the way he set Afghans up for failure," Barton said.
Hanson agrees that the US withdrawal has been "badly handled".
"On one hand, I can understand the US wanting to exit the country after two decades, but the way that it has been done has really been not something that has assisted the Afghanistan people," Hanson said.
Having spent 20 years holding back the Taliban, questions will linger over the speed at which they were able to make their way back to capital and raise their flag.
The rapidity of their campaign has even come as somewhat of a surprise to the Taliban itself, Hanson says.
But once they reached Kabul, the collapse of the government was all but certain. As night fell, Taliban fighters pledged to maintain law and order during the transition.
Reports from residents on the ground suggested otherwise, as some claimed to have witnessed looting in parts of the city, while the UN said it was receiving "chilling reports of severe restrictions on human rights throughout the country".
In the end, the events in Kabul marked the final chapter of America's longest war.
And, as 11 September again approaches, Afghanistan is as it was 20 years ago: under Taliban rule, its people fearing for the future and a risk to the security of the West.