The union flag was lowered at Camp Bastion, as Ben Brown reports
The last UK base in Afghanistan has been handed over to the control of Afghan security forces, ending British combat operations in the country.
The union flag was lowered at Camp Bastion, while Camp Leatherneck - the adjoining US base - was also handed over to Afghan control.
Defence Secretary Michael Fallon said "mistakes were made" but much had been achieved since troops arrived in 2001.
The number of deaths of British troops throughout the conflict stands at 453.
Camp Bastion, in Helmand Province, has been UK troops' main Afghan base since 2006.
The last US Marines unit in Afghanistan ended its combat operations with the handover of Camp Leatherneck. The US has lost 2,349 personnel in Afghanistan.
The UK and US flags have been lowered at Camp Bastion and Camp Leatherneck
As UK combat operations end, Afghan security forces will take an increased role
Mr Fallon said: "It is with pride that we announce the end of UK combat operations in Helmand, having given Afghanistan the best possible chance of a stable future.
"Our armed forces' tremendous sacrifice laid the foundations for a strong Afghan security force, set the security context that enabled the first democratic transition of power in the country's history, and stopped it being a launch pad for terrorist attacks in the UK."
He said the Taliban had not been defeated, but Afghan forces were now taking "full responsibilities".
Mr Fallon said UK support would continue through "institutional development", the Afghan National Army Officer Academy and development aid.
Speaking about the UK military mission, he said: "Mistakes were made militarily, mistakes were made by the politicians at the time and this goes back 10, 13 years.
"Clearly the numbers weren't there at the beginning, the equipment wasn't quite good enough at the beginning and we've learnt an awful lot from the campaign.
"But don't let's ignore what has been achieved."
Mr Fallon said the "vast bulk" of UK troops would be home by Christmas, with a "few hundred" staying to help with training at the officer academy.
"We're not going to send combat troops back into Afghanistan, under any circumstances," he added.
At the scene
Jonathan Beale, BBC defence correspondent, Camp Bastion
The Union flag has been flying in Helmand since 2006.
In a simple ceremony in Bastion - the now mostly empty main base for UK forces - it was lowered for the last time.
The moment was a symbol - for Britain at least - that its war in Afghanistan was over.
US marines alongside British and Afghan soldiers formed a guard of honour, saluting as the national anthems of all three countries were played over a loudspeaker.
It was a US-led ceremony with speeches by American and Afghan commanders.
There was no British voice.
As American marching tunes were piped over the sound system, the Afghan flag stood on its own.
The Afghans will now carry on a fight that's already claimed the lives of around 4,000 of their security forces this year.
As for the few remaining British troops in Bastion - about 300 - they will be leaving for good soon.
The UK's command of Helmand was transferred to US forces in April and personnel, military vehicles and kit have begun returning home in recent months.
At the height of the war in 2009, about 10,000 UK troops were based in Camp Bastion and the UK's 137 patrol bases in southern Afghanistan.
Only a small number of personnel are due to remain in the country after this year, at the British-run military academy in Kabul.
At the time Camp Bastion opened, the government said UK forces would be there to protect reconstruction of the country, but they got caught up in the struggle against the Taliban.
The sprawling base grew to the size of the town of Reading, with a perimeter of 22 miles. Its runway, which at one point became the fifth-busiest UK-operated airstrip, is now expected to handle commercial flights.
Chief of the General Staff, Gen Sir Nick Carter, told the Sunday Telegraph the handover of Camp Bastion would be significant "not least because of the sacrifice that so many people have made in Helmand".
He said: "They are going to have challenges, but I am absolutely confident that the majority of the population in central Helmand will be secured by Afghan forces."
Rear Adm Chris Parry, who helped plan the role of UK troops in Afghanistan, told the BBC that Britain's involvement had been "worth it", saying the country was now "more stable", was improving economically and had 40% more children going to school.
"We've got rid of al-Qaeda and the bulk of the Taliban from the country," he said.
"The Afghan security forces are a lot better than most people give them credit for, and most of the people I talk to say that they are well capable of actually holding down most of the major cities and centres of population."
With the UK and US handing over their bases, the Afghan flag will fly alone
British troops have been in Afghanistan since 2001, and 453 have died
But he said the UK plan in Afghanistan was "not the one I would have chosen" and showed a "classic breakdown in strategic thinking".
He said politicians did not know what they wanted to achieve, the military did not have enough resources and there was no "coherent military plan".
"I don't think the military leaders at the time had the courage to tell the politicians that it was a rotten plan," he said.
"At the time those of us who had alternative views tried to make our point. I'm afraid democracies, unless they're in total war, aren't very good at making strategic choices."