British Prime Minister Boris Johnson has written an open letter to the military, veterans and loved ones of those who lost their lives in active service in Afghanistan, saying he was "lost in admiration".
Members of the armed forces took part in Operation Pitting, which ended at weekend, to evacuate Afghanistan.
"There has been nothing like it in speed and scale, certainly in my lifetime," Mr Johnson wrote.
He recognised that watching the Taliban take over Afghanistan after 20 years would have been difficult for many to comprehend.
"Over the last two decades, many thousands of you dedicated years of your lives to service in Afghanistan, often in the most arduous conditions," Mr Johnson said.
"In particular, I realise that this will be an especially difficult time for the friends and loved ones of the 457 service personnel who laid down their lives."
He repeated his message that their sacrifice was not in vain.
"Our purpose in Afghanistan was simple – to protect the United Kingdom from harm – and you succeeded in that central mission," Mr Johnson said.
"In the last 20 years, not a single terrorist attack has been launched from Afghan soil against the UK or any other western country. I know this was not down to chance or good fortune.
"Our country was protected because you joined with our allies to fight Al Qaeda, destroy its training camps, disperse or eliminate its leaders, and weaken its very core.
"I would not wish to contemplate what might have happened if you had not carried out this vital task. You kept Al Qaeda from our door for two decades and we are all safer as a result.
"I want to take this opportunity to offer my profound thanks for everything you did and to say without hesitation that you should take the greatest pride in your achievements."
He spoke of their impact on the Afghan people, whether through girls’ education, the clearing of landmines, or many homes having electricity for the first time.
"I do not believe that any of these gains could swiftly be undone," Mr Johnson said.
"Education, once imparted, can never be taken away, and this progress would never have happened at all without your effort and sacrifice.
"Whether you are still serving or a veteran, a loved one, a relation or a friend, you all played your part and you should feel immense pride.
"The government will always stand by you.
"Do not lose sight of the essential fact that you fulfilled the first duty of the British Armed Forces – to protect our country – and we will be forever grateful that you did."