Islamic State immediately claimed responsibility for the attack in the capital Kabul, which also left 112 people injured.
Police said the suicide bomber targeted civilians who had gathered to receive national identification cards.
Windows in buildings miles away were shattered by the huge explosion which echoed across the city.
Police closed all roads around the site of the blast allowing only ambulances to pass.
TV stations broadcast live footage of hundreds of distraught people gathered at nearby hospitals seeking news about loved ones.
Najib Danish, interior ministry spokesman, posted on Facebook: “The final death toll from today’s terrorist attack in Kabul reached 48 martyred and 112 wounded.
“All the victims were civilians and women and children are among them.”
US ambassador John Bass wrote on Twitter: “This senseless violence shows the cowardice and inhumanity of the enemies of democracy and peace in Afghanistan.”
Islamic State claimed responsibility in a statement carried by its Aamaq news agency, saying it had targeted Shiite “apostates”.
Parliamentary elections are due to be held in Afghanistan in October and last week three police officers responsible for guarding voter registration centres in two Afghan provinces were killed by militants.
Afghan security forces have struggled to prevent attacks by the Islamic State and the Taliban since the US and NATO concluded their combat mission at the end of 2014.
Both groups launch attacks regularly, with the Taliban usually targeting the government and security forces, and IS attacking the country’s Shiite minority.
The groups want to establish a harsh form of Islamic rule in Afghanistan, and are opposed to democratic elections.
More from Afghanistan
Afghan toddler named after US President Trump
War in Afghanistan: Threat of attacks ‘worse than ever’
Afghan security: Britain ‘should commit more troops’
B-52 drops record number of smart bombs on Taliban
Millions of Afghan refugees facing deportation threat from Pakistan
Was the war in Afghanistan worth it?
In further violence in Afghanistan, at least five people were killed when their vehicle struck a roadside bomb in the northern Baghlan province.
In the northern Balkh province, a district police chief died of his wounds after being shot on Saturday during a gun battle with insurgents.