A wounded Afghan policeman is carried away from the site of a Taliban attack on British Council offices in Kabul. David Cameron has said the event will not stop British peace aims. Photograph: Ahmad Masood/Reuters

David Cameron has said the "vicious and cowardly" attack on the British Council building in Kabul on Friday will not stop Britain from trying to bring peace to Afghanistan.

The prime minister said there has been a "tragic loss of life", but paid tribute to the way the Afghan security forces and troops from New Zealand had brought the attack to an end.

"It's obviously a tragic [and] cowardly act that has been undertaken, but it won't succeed and it won't deflect us from the vital work we are doing in Afghanistan," he said.

"It will not stop the British Council and indeed our whole effort in Afghanistan to bring greater stability and peace to that country."

Britain is trying to build up the effectiveness of the Afghan security forces, and Cameron said Afghan soldiers had played a role in dealing with the attack on the British Council as well as an attack on the Intercontinental hotel in Kabul in June.

"I think what we saw both in this incident, and in the terrible incident at the Intercontinental hotel, is that actually on both occasions Afghan security forces were in the lead," he added.

"Yes, they had the assistance of international forces, New Zealand forces on this occasion, but they were in the lead. They did bring this to an end, the insurgents that did this are all now accounted for."

Cameron also said he had spoken to John Key, the prime minister of New Zealand, "to thank him for the incredibly brave and hard work of the New Zealand special forces, who helped bring this appalling incident to a close".

Douglas Alexander, the shadow foreign secretary, said in a statement: "This despicable and cowardly attack should be condemned unreservedly.

"I welcome the news UK nationals are safe and extend my sympathy to the families of those who have lost their lives.

"As well as the courage and bravery of Britain's armed forces, civilian staff in the British Council, British embassy and our aid workers do outstanding work in Afghanistan and will continue to have our full support in their efforts."