In the early 1990s, with Afghanistan in the chaos and corruption of civil war, the Taliban was formed in the southern province of Kandahar under the leadership of one-eyed warrior-cleric Mullah Omar.
Omar, who led them until his death in 2013, was from a stronghold of the powerful Pashtun ethnic group from which most Taliban fighters come.
Haibatullah Akhundzada is now the top leader, while Taliban co-founder Mullah Baradar heads the political wing.
Dramatic rise to power
Promising to restore order and justice, the Taliban rose dramatically.
They drew substantial support from Pakistan and initially had the tacit approval of the United States.
In 1994 they seized the city of Kandahar almost without a fight.
Equipped with tanks, heavy weapons and the cash to buy the support of local commanders, they steadily moved north, before capturing the capital Kabul on 27 September 1996.
President Burhanuddin Rabbani had already fled.
Taliban fighters dragged former communist president Mohammed Najibullah from a United Nations office where he had been sheltering, and hanged him in a public street after torturing him.
Reign of terror
The Taliban government imposed the strictest interpretations of sharia, establishing religious police for the suppression of "vice".
Music, television and popular pastimes such as kite-flying were banned. Girls' schools were closed, while women were prevented from working and forced to wear an all-covering burqa in public.
The 11 September 2001 attacks that killed around 3,000 people in the US were immediately blamed on Al-Qaeda.
Accusing the Taliban of refusing to hand over Bin Laden, the US and allies launched air strikes on Afghanistan in October.
By early December the Taliban government had fallen, its leaders fleeing to their strongholds in the south and east, or across the border into Pakistan's tribal zone.
At first written off as a spent force, the Taliban rebuilt to lead an insurgency against the new Western-backed government.
Making heavy use of improvised bombings and suicide attacks, they labelled as "crusaders" the tens of thousands of foreign troops who deployed into the country as part of a US-dominated NATO force.
The NATO combat mission ended in December 2014 and the bulk of Western forces withdrew.
In July 2015 Pakistan hosted the first direct talks between Afghan and Taliban leaders, with support from China and the US, but they collapsed after Mullah Omar's death was revealed.
The rival Islamic State jihadist group emerged in Afghanistan in 2015, launching its own series of devastating attacks, mainly on Kabul.
US exit, Taliban offensive
In 2018 the US and Taliban began discreet talks in Doha, that were interrupted several times after attacks against American troops.
A historic deal was signed by the US with the Taliban in Doha on 29 February 2020, laying out a timetable for a full American troop withdrawal.
On 6 July 2021, the US military said it had completed 90 per cent of its retreat from Afghanistan.
Five weeks later, the Taliban are on the outskirts of the capital Kabul, and the government has conceded it is preparing for a "transfer of power".