0523 GMT September 23, 2019
No group has claimed responsibility for the raid, which caps a bloody year for Afghanistan as long-suffering civilians and security forces are slaughtered in record numbers.
Taliban spokesman Zabiullah Mujahid told AFP the attack had "nothing to do with the militants".
Another 27 people were wounded in Monday's massacre on a site where the Ministry of Public Works and an office that handles pensions and benefits for war veterans are located, Health Ministry spokesman Waheed Majroh said.
Gunmen stormed the compound mid-afternoon after detonating two car bombs at the main entrance, which is opposite residential apartment blocks.
As they entered two buildings belonging to the Ministry of Public Works and the organization responsible for supporting war veterans and their families, terrified workers ran for their lives. Some jumped from windows several floors up to escape the militants.
The blasts may have been decoys, according to witnesses who saw several militants enter the compound through a back gate.
Hundreds were trapped inside for hours as heavily armed security forces swarmed the area, engaging the attackers in a fierce gun battle punctuated by multiple explosions.
Public Works Ministry employee Amdullah Barekzai hid under his desk for five hours, listening to gunfire and blasts inside his building.
"When the security forces took us from the office, I saw many bodies covered in blood, lying in the corridors," Barekzai said.
At least four militants were killed and more than 350 people freed, officials said. Most of the dead and wounded were civilians, who have borne the brunt of the 17-year war.
"It was a barbaric attack against humanity," Interior Ministry spokesman Najib Danish told reporters.
It was the deadliest assault in the Afghan capital since a suicide bomber blew himself up in the middle of a religious gathering last month, killing at least 55 people.
President Ashraf Ghani, whose government has been skewered over its security failures, said "terrorists attack civilian targets to hide their defeat on the battleground".
Afghanistan's de facto prime minister Abdullah Abdullah also sounded a defiant note as he blamed the Taliban for the attack.
"Every attack they carry out against our people, our resolve is further strengthened to eliminate them," he said.
But their statements belie the grim reality on the battlefield where the Taliban have the upper hand.
Afghanistan's largest militant group has made significant territorial gains this year as its fighters inflict record casualties on government forces.