British troops will begin their withdrawal from Afghanistan next month alongside other NATO allies.
Foreign Secretary Dominic Raab said: "We will support an orderly departure of our forces, while building up Afghanistan’s capacity for self-governance, and continuing counter-terrorism support – to protect the gains made over the last 20 years."
NATO said on Wednesday that the withdrawal of around 7,000 non-US troops from NATO countries alongside Australia, New Zealand, and Georgia, would be complete "within a few months".
The alliance’s Secretary General Jens Stoltenberg said: "This is not an easy decision, and it entails risks.
"As I said for many months, we face a dilemma.
"Because the alternative to leaving in an orderly fashion is to be prepared for a long-term, open-ended military commitment with potentially more NATO troops."
The US withdrawal will be complete by 11 September, the date marking 20 years since al Qaeda attacked the US with hijacked passenger planes.
More than 3,000 people were killed in the 2001 attacks, prompting the US and its allies to invade Afghanistan, where the Taliban was blamed for providing a haven to al Qaeda leader Osama bin Laden and his extremists.
Among the reasons for the coordinated withdrawal are that NATO allies rely on US airlift capabilities and they will also want to prevent hardware falling into the hands of militants, which happened after the US left Iraq.
But there are concerns about what will happen in Afghanistan after the withdrawal, with the country’s factions struggling to make progress in peace talks.
One of the main parts of NATO’s mission was to train and equip Afghan security forces but they face a difficult fight against the militant insurgency.
Former defence minister Tobias Ellwood said the US withdrawal risked "losing the peace".
Speaking to Times Radio, Mr Ellwood said: "We don’t put enough effort into the stabilisation and the peacekeeping, the nation building, and encouraging better governance, better security, that indigenous capability so they can look after their own affairs.
"Instead, as we’ve seen in Iraq as well, we defeat the bad guys and then we withdraw, we don’t do enough to then lift the country off its knees.
"And I fear that we will see – in fact it’s happening already – is extremism will regroup in Afghanistan in the way that it’s regrouping in Iraq, and indeed, to some degree in east Africa as well."
Mr Stoltenberg said: "This is not the end of our relationship with Afghanistan but rather the start of a new chapter. NATO allies will continue to stand with the Afghan people but it is now for the Afghan people to build a sustainable peace that puts an end to violence."
The defence secretary Ben Wallace said: "The people of Afghanistan deserve a peaceful and stable future.
"As we drawdown, the security of our people currently serving in Afghanistan remains our priority and we have been clear that attacks on allied troops will be met with a forceful response.
"The British public and our armed forces community, both serving and veterans, will have lasting memories of our time in Afghanistan.
"Most importantly we must remember those who paid the ultimate sacrifice, who will never be forgotten."
British forces ended combat operations in Afghanistan in 2014 but some personnel remained in non-combat roles.