More than 1,700 civilians have been killed in attacks in Afghanistan so far this year, hitting confidence in the Western-backed government of President Ashraf Ghani.
Abdulhai Walizada, a local police spokesman, said there appeared to be more than one attacker on Tuesday, with witnesses describing a suicide bomber who detonated explosives and at least one other, a gunman who threw grenades at worshippers.
Mohammad Asif Rahimi, governor of Herat, said at least 29 people were killed and 64 wounded in the incident which came two months after an attack on a 12th century mosque known as the Jama Masjid in Herat, in which seven people died.
There was no claim of responsibility. But the Taliban, fighting to install strict Islamic law and drive foreign troops out of Afghanistan, denied any involvement.
Ghani, whose government has been under mounting pressure because of deteriorating security across the country, condemned the bombing and called on religious scholars to "raise their voices against the terrorist attacks".
Afghanistan has traditionally been relatively free of the sectarian violence common in Iraq or Syria but hardline Sunni militants from the local branch of Islamic State have repeatedly attacked the mainly Shi'ite Hazara minority in the past year.
The latest attack comes as the U.S. administration considers sending more troops to Afghanistan to bolster the NATO-led coalition advising and assisting Afghan security forces.