There was no immediate claim of responsibility but the Taliban was quick to deny involvement in the assault near the Afghan Voice Agency, a media outlet which earlier reports had suggested could have been the target.
Deputy interior ministry spokesman Nasrat Rahimi told AFP the blasts were in fact aimed at the Shia Tabayan cultural centre.
"A ceremony was being held to mark the 38th anniversary of Soviet invasion in Afghanistan when the explosion went off," he said.
"We have 40 killed, 30 wounded, but this is not the final toll. It might go up."
Rahimi said the main blast was followed by two smaller bomb explosions that did not cause casualties.
Kabul has become one of the deadliest places in war-torn Afghanistan for civilians in recent months, as the Taliban step up their attacks and the ISIS seeks to expand its presence in the country.
Friday's assault comes days after a suicide bomber killed six civilians in an attack near an Afghan intelligence agency compound in the city, which was claimed by IS.
The Middle Eastern terror group has gained ground in Afghanistan since it first appeared in the region in 2015 and has scaled up its attacks in Kabul, including on security installations and the country's Shia minority.
A hospital official told local TV that 18 wounded had been brought to his facility.
"Five of the wounded are in critical condition and our doctors are working to save their lives," Sabir Nasib, head of Istiqlal hospital, said.
A man attending the anniversary ceremony said he heard a "big boom".
"We do not know the numbers (of casualties). When the explosion happened we immediately fled," he told Tolo News.
Mohammad Hasan Rezayee, a university student also at the ceremony, told Tolo News he had suffered burns to his face in the blast.
"After the blast there was fire and smoke inside the building and everyone was pleading for help," he said.