"One police and one special forces member were also killed", Najib Danish, deputy interior ministry spokesman, told AFP, adding that the attack was over.
But the ministry spokesman Ismail Kawoosi said the casualties may increase - after they received final information on the incident.
Police who had surrounded the building said the attack had caused some casualties and they were preparing to try to clear the mosque.
Witnesses and residents said the explosion occurred inside the Imam Zaman mosque complex in Qala-e-Najarha area, Tolo News reported.
According to him, at least 12 people were killed and 38 others were wounded in the attack.
The police apologized and said they could not allow her to pass because fighting was underway, and asked a couple of elders to help console the woman and take her away.
The mosque, in a residential area in the north of the city, was believed to have been packed with dozens of men, women and children when the assailants struck during Friday prayers.
The attack took place in the capital Kabul and according to reports a blast hit the mosque first and then gunfire began.
While the fierce gun battle was underway, another explosion occurred close to Imam Zaman Mosque.
The presidential palace issued a statement condemning the attack as an act of "cowardice" and vowing to punish the "criminal terrorists".
The IS group's news outlet Amaq said IS militants had carried out a "commando" attack on the mosque.