A group called the Taliban had controlled most of the country since 1996 but they were overthrown in November 2001 by British and American armed forces, as well as lots of Afghan fighters from a group called the Northern Alliance.
Why was there a war?
During the time that the Taliban controlled Afghanistan, they allowed an organisation called al-Qaeda to have training camps there.
In September 2001, nearly 3,000 people were killed in the 9/11 terrorist attacks. The United States believed that Osama Bin Laden - who was the head of al-Qaeda - was the man behind these attacks.
There was a lot of international pressure on the Afghan leaders to hand over Osama Bin Laden. When the Taliban didn't do this, the United States decided they would use their armed forces.
In October 2001, the USA began bombing Afghanistan. They targeted bin Laden's al-Qaeda fighters and also the Taliban.
In November 2001, the Northern Alliance took control of the Afghan capital Kabul. They were being helped by the US and other countries that agreed with it, including the UK.
The Taliban were quickly driven out of the capital city, Kabul, but even today Afghanistan remains a dangerous place.
It was in 2011, ten years after the war in Afghanistan began that Osama bin Laden was eventually found by American soldiers in Pakistan, where he was shot and killed.
British troops and forces from other countries are still in Afghanistan, trying to help the government build a stable nation.
The UK government plans to take all troops out of Afghanistan by the end of 2014.