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.
Zalmai Alokzai, a local businessman who rushed to a hospital to check whether doctors needed blood donations, described seeing chaotic scenes after the attack.
"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.
There are fears that the death toll will rise further.
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.
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.
It came two decades after US forces had removed the militants from power in 2001.