Bodies were seen scattered inside the Said Abad mosque, used by the minority Shia Muslim community.
More than 100 people were injured in the blast in the northern city.
The Islamic State group said it was behind the attack. Sunni Muslim extremists have targeted Shias who they see as heretics.
IS-K, the Afghan regional affiliate of the IS group that is violently opposed to the governing Taliban, has carried out several bombings recently, largely in the east of the country.
An IS suicide bomber reportedly detonated an explosive vest as worshippers gathered inside the mosque for Friday prayers.
“Ambulances were going back to the incident scene to carry the dead,” he told AFP news agency.
Local security officials were quoted by Tolo News as saying that more than 300 people were attending the prayers when the attack happened.
The United Nations said Friday’s bombing was a “third deadly attack this week apparently targeting a religious institution” and was part of a “disturbing pattern of violence”.
The UN referred to Sunday’s bombing near a mosque in the capital Kabul that left several people dead, and an assault on a madrassa (educational institution) in the eastern city of Khost on Wednesday.
A significant threat to the Taliban
While there has been no claim of responsibility so far, this attack bears all the hallmarks of IS-K, the group that targeted Kabul airport in a devastating bombing in August.
The group has repeatedly targeted Afghanistan’s Shia minority in the past, with suicide bombers striking at mosques, sports clubs and schools. In recent weeks, IS has also stepped up a campaign of attacks against the Taliban.
IS targeted a funeral prayer service attended by a number of senior Taliban leaders in Kabul on Sunday, and there have been a spate of smaller attacks in the eastern provinces of Nangarhar and Kunar, where IS previously had its stronghold.
Friday’s attack, if it has been carried out by IS, would mark a grim expansion of their activities into the north of the country. The Taliban say they have arrested dozens of members of IS and are believed to have killed others suspected of links to the group, but publicly they have also played down the threat IS poses.
Many Afghans hoped that the Taliban’s takeover would at least herald a more peaceful, if authoritarian, era. But IS represents a significant threat to the Taliban’s promise of improved security.
The Taliban took control of Afghanistan after foreign forces withdrew from the country at the end of August following a deal agreed with the US.