There have been more than 400 deaths since 2001 but the UK presence has cut the number of terrorist plots, he said.
The prime minister played table football and attended a carol service with troops in Helmand province.
Troop numbers will nearly halve to 5,200 in 2013, he announced this week.
On his traditional seasonal visit to troops, Mr Cameron toured Camp Bastion and was taken by helicopter to the smaller Camp Price operating base about 20 miles (32km) away.
All Nato operations are due to finish by the end of 2014, with responsibility being transferred to Afghan forces.
And Mr Cameron suggested the Afghans are acquiring the "capability" to take charge of security.
"This is withdrawal. This is draw-down based on success not on failure," he said.
"We're confident it can be done while making sure Afghanistan does not return to become a haven of terrorism, which is of course why we came here in the first place."
He added: "We have paid a very heavy price but I think the reason for coming here in the first place, which was to stop Afghanistan being a haven for terror... I think it was the right decision."
Equipment boost David Cameron plays table football with Royal Marines at Forwarding Operating Base PriceAt Prime Ministers Questions on Wednesday, Mr Cameron said that almost half of the current force serving in Helmand province are to be withdrawn from Afghanistan next year.
Troop numbers are already being reduced from 9,500 to 9,000 before Christmas. And numbers would fall to about 5,200 by the end of 2013, he said.
A small number of British troops would remain in the country beyond that, working at an officer training academy and "involved in returning equipment and dealing with logistics," Mr Cameron added.
But during his visit to Afghanistan, government officials promised an extra £230m from Treasury reserves will be spent on military kit to see the campaign through.
The funding includes £29m for additional bomb detectors; a £10m upgrade for armed vehicles; more military dogs for foot patrols and a £5m boost intelligence for surveillance and reconnaissance at Camp Bastion.