The attack, which ended a period of relative calm in the capital, came as U.S. special peace envoy Zalmay Khalilzad held a seventh round of peace talks with the Taliban in Qatar, aimed at bringing the 18-year-old war to an end.
After the blast, five gunmen took up positions in an unfinished building nearby, shooting at rescuers and fighting a battle with security forces for seven hours before themselves being killed.
The Taliban claimed responsibility for the attack.
"The target was the Defence Ministry's technical installation," spokesman Zabihullah Mujahid said in a statement.
"Clashes ended with the death of all five attackers," said Interior Ministry spokesman Nasrat Rahimi. "Four civilians and two policemen were killed." He said more than 210 people had been rescued during the operation.
About 100 wounded people were taken to hospital, the Health Ministry said.
Fifty-one children in two schools near the blast site were hurt by flying shards of glass, the Education Ministry said.
The Pashto-language Shamshad TV, whose office was near the blast site, said one of its security guards had been killed and several employees had been hurt in the blast, which sent a plume of black smoke rising over the city and shook buildings.
The area has a cluster of military and government buildings, as well as an office belonging to the Afghan Football Federation, whose chief, Yosuf Kargar, was among several staff who were injured, according to spokesman Shafi Shadab.
President Ashraf Ghani called the attack on civilians a crime against humanity.
The Qatar talks have focused on issues ranging from counter-terrorism and withdrawal of foreign troops to an intra-Afghan dialogue and a comprehensive ceasefire.
Two sources at the talks said direct negotiations were unlikely to go beyond Monday, but there was no word of any official suspension.
However, one official present at the talks in Doha said that "the latest attack by the Taliban has changed the entire context of our meeting - unease has crept in".
Sohail Shaheen, spokesman for the Taliban political office in Doha, said the group's key concern was to make sure a timeline for a foreign troop pullout was announced.
Taliban officials have previously said they want all foreign troops withdrawn before they hold talks with the Afghan government or declare a ceasefire.
About 20,000 foreign troops, most of them American, are in Afghanistan as part of a U.S.-led NATO mission to train, assist and advise Afghan forces. Some U.S. forces carry out counter-terrorism operations.
Less than a week ago, U.S. Secretary of State Mike Pompeo said in Kabul that the Trump administration was hopeful that a peace deal with the Taliban could be achieved by Sept. 1.
Despite peace talks gaining momentum, fighting between the Taliban and Afghan forces who are backed by the foreign troops has raged across Afghanistan.
The Ministry of Defence said on Monday that 67 insurgents had been killed in 11 provinces in the previous 24 hours. The Taliban said their fighters had conducted 52 operations against Afghan forces in which more than 170 people had been killed.
Both sides accuse each other of exaggerating casualty figures.
This story has been published from a wire agency feed without modifications to the text. Only the headline has been changed.