Click to play
Officials say at least seven people, including four policemen, were killed as well as nine of the insurgents.
The attack, the most complex in Kabul to date, comes as US and other foreign forces begin to withdraw their troops.
Nato and the US embassy said none of their staff were among the casualties.
The Taliban said it was behind the attack, although Afghan officials blamed the Haqqani network, an insurgent group linked to the Taliban and al-Qaeda but which operates independently.
Afghan forces worked their way through the multi-storey building which overlooks the heavily fortified diplomatic quarter, exchanging fire with the militants on the floors above well into Wednesday.
Afghan officials then confirmed that all the attackers were dead and the fighting was over."Conditions in Kabul city are back to normal and all our countrymen can go about their daily lives without any worries," said an interior ministry spokesman.
US Army helicopters and an Afghan army MI-35 attack helicopter had been involved in the operation.
Intelligence officials have been going through the lower floors, gathering evidence about the way the assault was planned and carried out.
Officials told the BBC the attackers had left behind explosives and burkas in a van on the site and that each of the attacker had been carrying hand grenades, pistols and an army knife. Their suicide vests also contained ballbearings, said the officials.
Suicide attackers The attack began at about 13:30 local time (09:00 GMT) on Tuesday when a car packed with insurgents was stopped at a checkpoint at Abdul Haq Square about 1km from the US embassy.
Witnesses said there were several large explosions and the insurgents entered a nearby nine-storey building under construction.
From there, up to five militants opened fire on the embassy complex with machine guns, rocket-propelled grenades and possibly a mortar.
The BBC's Quentin Sommerville in Kabul says the attackers had clearly come prepared for a long fight and are thought to have spent three days accumulating weapons in the building.
While the fighting was going on, Frozan Hemati, a doctor who lives in the Macrorayon district, told the BBC: ''We haven't been able to sleep, especially the children. All night gunfire shook the windows and woke us up."
There was a simultaneous barrage of explosions around the nearby Wazir Akbar Khan area, witnesses said.
At the same time in the west of the city, two suicide attackers detonated explosives outside a police station.
A third was killed as he tried to make it into the airport. A jail run by the intelligence service was also a target.
A Taliban spokesman said the group was carrying out "a massive suicide attack on local and foreign intelligence facilities".Haroun Mir, director of the Kabul-based Afghanistan Centre for Research and Policy Studies, said it was the first time that four groups of militants had attacked in four different places.
"This is new as previously we had one or maximum two attacks. The Haqqani network has the full support of al-Qaeda and has the capacity to execute sophisticated attacks. It is the only group with this capacity."
Afghan President Hamid Karzai condemned the attacks, saying they would not deter Afghan forces from taking full responsibility for security by the time international combat troops withdraw.
"By carrying out such attacks terrorists cannot stop the transition of security from international to Afghan forces," he said in a statement.
Earlier this year, Nato's International Security Assistance Force (Isaf) handed over responsibility for security in seven areas of Afghanistan, including two provinces.