Fighting in the Afghan capital Kabul has finally ended - about 18 hours after the Taliban launched their assault, local officials have said.
A spokesman for Kabul's police chief said the last gunman, who was fighting near the parliament in the west of the city, was killed early on Monday.
Security forces earlier flushed out insurgents in the central diplomatic area, home to several embassies.
The officials said 36 gunmen and eight members of Afghan security forces died.
Three civilians were also killed, Afghan Interior Minister Besmillah Mohammadi told reporters on Monday.
He added that about 65 people - including 25 civilians - were injured.
Attackers also carried out raids in the provinces of Logar, Paktia and Nangarhar.
In Kabul, foreign embassies, Nato's headquarters and the Afghan parliament were hit in the first major attack on the city in more than six months.
"The latest information we have about the Afghan parliament area is that the attack is over now and the only insurgent who was resisting has been killed," said the Kabul police chief's spokesman Hashmatullah Stanikzai.
In the central district of Wazir Akbar Khan, officials said Afghan and Norwegian special forces raided a construction site which the attackers had been using as a base.
Video footage showed soldiers scaling the scaffolding after dawn on Monday, as bullets blasted off walls around them.
The BBC's Bilal Sarwary in Kabul says there were reports that the gunmen took several construction workers hostage.
"I could not sleep because of all this gunfire now. It's been the whole night," local resident Hamdullah told Reuters.
Afghan officials said they have also arrested two would-be suicide bombers, who intended to kill the second vice-president, Mohammad Karim Khalili.
The Taliban said the co-ordinated attacks were a response to recent claims by Nato officials that the insurgency was weak.
"These attacks are the beginning of the spring offensive and we had planned them for months," Taliban spokesman Zabihullah Mujahid told Reuters.
There were also reports that militants from the Haqqani group took part in the assault.
The Haqqanis - who are based along the Afghanistan-Pakistan porous border - have grown from a CIA-backed anti-Soviet group in the 1980s into one of the most feared anti-Western militant organisations in the region.
The group has been blamed for several high-profile attacks against Western, Indian and government targets in Afghanistan, including a major assault in Kabul last September.
Afghan lawmaker Shukria Barakzai told the BBC that she was sceptical about the ability of Afghan security forces to deal with insurgents without foreign support.
She said she wanted "a clear answer" from the authorities about why it had taken so long to fight off the assault.
Correspondents say the attacks have shattered the confidence of Afghans, as the insurgents have once more shown that they can strike right in the heart of Kabul.
The fighting has also raised concern about security as Nato prepares to withdraw its troops by the end of 2014 and hand over responsibility to Afghan forces.
Elsewhere in the country, gunmen attacked government buildings in Logar province, the airport in the eastern city of Jalalabad, and a police facility in the town of Gardez in Paktia province.