The Taliban were removed from power in Afghanistan by US-led forces in 2001, but the group has been on the offensive in recent months and is now on the brink of seizing power again.
As the US prepared to complete its withdrawal by September 11, after two decades of war, the militants took major cities and have now reached the outskirts of the capital Kabul.
The group entered direct talks with the US back in 2018, and in February 2020 the two sides struck a peace deal in Doha that committed the US to withdrawal and the Taliban to prevent attacks on US forces.
Other promises included not allowing al-Qaeda or other militants to operate in areas it controlled and proceeding with national peace talks.
But in the year that followed, the Taliban continued to target Afghan security forces and civilians and advanced rapidly across the country.
Rise to power
The Taliban, or "students" in the Pashto language, emerged in the early 1990s in northern Pakistan following the withdrawal of Soviet troops from Afghanistan. It is believed that the predominantly Pashtun movement first appeared in religious seminaries - mostly paid for by money from Saudi Arabia - which preached a hardline form of Sunni Islam.
The promise made by the Taliban - in Pashtun areas straddling Pakistan and Afghanistan - was to restore peace and security and enforce their own austere version of Sharia, or Islamic law, once in power.
From south-western Afghanistan, the Taliban quickly extended their influence. In September 1995 they captured the province of Herat, bordering Iran, and exactly one year later they captured the Afghan capital, Kabul, overthrowing the regime of President Burhanuddin Rabbani - one of the founding fathers of the Afghan mujahideen that resisted the Soviet occupation. By 1998, the Taliban were in control of almost 90% of Afghanistan.
Afghans, weary of the mujahideen's excesses and infighting after the Soviets were driven out, generally welcomed the Taliban when they first appeared on the scene. Their early popularity was largely due to their success in stamping out corruption, curbing lawlessness and making the roads and the areas under their control safe for commerce to flourish.
But the Taliban also introduced or supported punishments in line with their strict interpretation of Sharia law - such as public executions of convicted murderers and adulterers, and amputations for those found guilty of theft. Men were required to grow beards and women had to wear the all-covering burka.
The Taliban also banned television, music and cinema, and disapproved of girls aged 10 and over going to school. They were accused of various human rights and cultural abuses. One notorious example was in 2001, when the Taliban went ahead with the destruction of the famous Bamiyan Buddha statues in central Afghanistan, despite international outrage.
Pakistan has repeatedly denied that it was the architect of the Taliban enterprise, but there is little doubt that many Afghans who initially joined the movement were educated in madrassas (religious schools) in Pakistan.
Pakistan was also one of only three countries, along with Saudi Arabia and the United Arab Emirates (UAE), which recognised the Taliban when they were in power in Afghanistan. It was also the last country to break diplomatic ties with the group.
At one point, the Taliban threatened to destabilise Pakistan from areas they controlled in the northwest. One of the most high-profile and internationally condemned all Pakistani Taliban attacks took place in October 2012, when schoolgirl Malala Yousafzai was shot on her way home in the town of Mingora.
A major military offensive two years later following the Peshawar school massacre greatly reduced the group's influence in Pakistan though. At least three key figures of the Pakistani Taliban had been killed in US drone strikes in 2013, including the group's leader, Hakimullah Mehsud.
The attention of the world was drawn to the Taliban in Afghanistan in the wake of the 11 September 2001 World Trade Center attacks in New York. The Taliban were accused of providing a sanctuary for the prime suspects - Osama Bin Laden and his al-Qaeda movement.
On October 7, 2001, a US-led military coalition launched attacks in Afghanistan, and by the first week of December the Taliban regime had collapsed. The group's then-leader, Mullah Mohammad Omar, and other senior figures, including Bin Laden, evaded capture despite one of the largest manhunts in the world.
Many senior Taliban leaders reportedly took refuge in the Pakistani city of Quetta, from where they guided the Taliban. But the existence of what was dubbed the "Quetta Shura" was denied by Islamabad.
Despite ever higher numbers of foreign troops, the Taliban gradually regained and then extended their influence in Afghanistan, rendering vast tracts of the country insecure, and violence in the country returned to levels not seen since 2001.
There were numerous Taliban attacks on Kabul and, in September 2012, the group carried out a high-profile raid on Nato's Camp Bastion base.
Hopes of a negotiated peace were raised in 2013, when the Taliban announced plans to open an office in Qatar. But mistrust on all sides remained high and the violence went on.
In August 2015, the Taliban admitted they had covered up Mullah Omar's death - reportedly of health problems at a hospital in Pakistan - for more than two years. The following month, the group said it had put aside weeks of infighting and rallied around a new leader in the form of Mullah Mansour, who had been the deputy of Mullah Omar.
At around the same time, the Taliban seized control of a provincial capital for the first time since their defeat in 2001, taking control of the strategically important city of Kunduz.
Mullah Mansour was killed in a US drone strike in May 2016 and replaced by his deputy Mawlawi Hibatullah Akhundzada, who remains in control of the group.
Countdown to withdrawal
In the year following the US-Taliban peace deal of February 2020 - which was the culmination of a long spell of direct talks - the Taliban appeared to shift its tactics from complex attacks in cities and on military outposts to a wave of targeted assassinations that terrorised Afghan civilians.
The targets - journalists, judges, peace activists, women in positions of power - appeared to suggest that the Taliban had not changed their extremist ideology, only their strategy.
Despite grave concerns from Afghan officials over the government's vulnerability to the Taliban without international support, the new US president, Joe Biden, announced in April 2021 that all American forces would leave the country by 11 September - two decades to the day since the felling of the World Trade Center. media captionHibatullah Akhundzada is a religious scholar and he is the former head of the Taliban courts
Having outlasted a superpower through two decades of war, the Taliban began seizing vast swathes of territory, threatening to once again topple a government in Kabul in the wake of a foreign power withdrawing.
The group is thought to now be stronger in numbers than at any point since they were ousted in 2001 - with up to 85,000 full-time fighters, according to recent Nato estimates.
The advance has been more rapid than many had feared. General Austin Miller, the commander of the US-led mission in Afghanistan, warned in June that the country could be on a path towards a chaotic civil war, which he called a "concern for the world".
However, in many cases, the Taliban have been able to take over major cities without a fight, as government forces surrendered to avoid civilian casualties.
A US intelligence assessment the same month reportedly concluded that the Afghan government could fall within six months of the American military departure.