KABUL (Reuters) - British Prime Minister David Cameron made an unannounced visit to Afghanistan on Friday to meet the new unity government, the first major Western leader to visit since an election stalemate was resolved, easing threats of armed conflict.

Cameron met both new President Ashraf Ghani and chief executive Abdullah Abdullah and praised both British troops' accomplishments in the long war against the Islamist Taliban and also the newly trained Afghan security forces, who number around 350,000.

"It is striking how far they have come," he said in Kabul of Afghanistan's army and police forces.

"If the Taliban want to secure a role in the future of Afghanistan, then they must accept they have to give up violence and engage in the political process. That is the way to have a voice in this democratic country."

Cameron confirmed that all British combat troops would leave Afghanistan at the end of the year but said London would continue to provide 178 million pounds ($268.1 million) per year to support Afghanistan's government until at least 2017.

Britain has fewer than 5,000 of the about 50,000 service members in the U.S.-led military coalition in Afghanistan.

Cameron's visit comes four days after new Ghani was sworn into office after months of political turmoil following disputed elections.

The prolonged standoff over the June runoff vote between Ghani and rival Abdullah ended with a political deal that made Ghani president and saw Abdullah appointed to a chief executive's position with broad powers.

Behind the United States, Britain has been the second-largest contributor to the international military coalition that has been in Afghanistan since the 2001 U.S.-led intervention to topple the Taliban's radical Islamist regime in the wake of the Sept. 11 terrorist attacks on the United States.

More than 450 British troops have been killed in Afghanistan during the subsequent war.

(Reporting by Kay Johnson; Editing by Nick Macfie)