President Hamid Karzai of Afghanistan has linked Sunday's militant attacks to intelligence failures, especially on the part of Nato.

In his first response to the attacks, Mr Karzai praised the performance of the Afghan security forces.

He said they had proved themselves capable of defending their country.

Officials say 51 people died in the fighting in Kabul and elsewhere: four civilians, 11 members of the security forces and 36 insurgents.

"The terrorists' infiltration in Kabul and other provinces is an intelligence failure for us and especially for Nato and should be seriously investigated," Mr Karzai said.

Despite the rhetoric of not needing international support, this underlines dread about the future In pictures: Taliban 'spring offensive'

On Sunday, militants attacked the district in central Kabul where many embassies are located, as well as the parliament building. Nato's headquarters in the city also came under assault.

The clashes in the city ended on Monday, 18 hours after they began, when the last gunman, who was fighting near the parliament in the west of the city, was killed.

Earlier on Monday morning, Afghan special forces flushed out gunmen who had been using a central Kabul construction site as a base from which to fire on foreign embassies and other targets.

Afghan security sources have told the BBC British special forces were eventually called in to help end the battle.

The US, German and British embassies were among the diplomatic missions targeted.

'Spring offensive'

Insurgents also carried out attacks in Nangarhar, Logar and Paktia provinces.

The Taliban say they carried out the raids as part of a co-ordinated "spring offensive". The group usually ramps up its attacks on Nato and government forces in spring, after a relative lull over the winter, when snows hamper the fighters' movements.

Image caption The attackers used a construction site in central Kabul as a base

But the US ambassador to Kabul, Ryan Crocker, said he believed the Taliban would not have had the ability to carry out the attacks.

He told CNN he believed they were the work of the Haqqani network, a Pakistan-based militant group allied to the Taliban.

Mr Karzai's office said four civilians had died in the fighting. Earlier, Afghan Interior Minister Besmillah Mohammadi said that about 65 people - including 25 civilians - had been injured.

President Karzai paid tribute to the "bravery and sacrifice of the security forces who quickly and timely reacted to contain the terrorists", AFP news agency reports.

Afghan forces are expected to shoulder increasing responsibility for security as Nato countries wind down their troop presence ahead of a full withdrawal scheduled for the end of 2014.

High-profile attacks on Kabul 15 April 2012: Seven sites including parliament, Nato HQ and foreign embassies attacked

13 September 2011: Gunman seize unfinished high-rise to fire on Nato HQ and US embassy

19 August 2011: Gunman storm British Council HQ, killing 12 people

"I am enormously proud of how quickly Afghan security forces responded to attacks in Kabul," said Gen John Allen, commander of the Nato-led International Security Assistance Force (Isaf).

"They were on scene immediately, well-led and well-coordinated. They integrated their efforts, helped protect their fellow citizens and largely kept the insurgents contained."

But a source quoted by AFP said he did not share Nato's optimism.

"It's true that [the Afghan forces] did it better than in the past - there is progress," he said, on condition of anonymity.

"But still, to build up so many attacks and being able to launch them simultaneously demonstrates clearly [the Taliban's] ability to strike where and when they want."

The BBC's Bilal Sarwary says the authorities will be worried by the fact that, in contrast to previous attacks, the militants managed to penetrate the Wazir Akbar Khan diplomatic district - the "ring of steel" around central Kabul.

While the Taliban have said they carried out the attacks, analysts say they bear the hallmarks of the Haqqani network.