Suicide bomb explosion was followed by four hours of gunfight that ended after Afghan forces killed all attackers.
A suicide attack at a packed Shia mosque in the western Afghan province of Herat has killed dozens of people and injured scores, officials and eyewitnesses said.
The exact death toll from Tuesday’s blast was unclear.
At Herat Main Hospital, Dr Shehrzai confirmed that 29 bodies were brought to the medical facility soon after the blast.
Officials feared a rising toll with several of the more than 60 people injured in a critical condition.
Earlier, the provincial governor’s spokesman, Jalani Farhad, told Al Jazeera that the death toll had risen to 50.
“At around 8:00pm (15:30 GMT) tonight, a terrorist attack was carried out on a mosque in the third security district of Herat city,” Herat police spokesman Abdul Ahad Walizada told AFP news agency.
“Based on our initial information two terrorists were involved one of them wearing a suicide vest, who detonated himself while the second one was armed with a rifle. They are both dead,” he added.
The attack took place in the middle of evening prayers when the mosque was packed with about 300 worshippers.
Packed with worshipers
Hadid said he rushed to the mosque after hearing about the explosion.
He was told the attacker first fired on the private guards outside the mosque before entering. When inside, he fired on the praying worshippers until his rifle jammed, then he blew himself up.
Later, local residents, who are mostly Shia Muslims, attacked the police station pelting it with stones and setting it on fire, said Jalani Farhad, the provincial governor’s spokesman. They were apparently angry at the late response of the police.
Shia Muslims are a persecuted minority in Afghanistan and have been threatened by the affiliate of the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group that operates in the country’s east.
Taliban spokesman Qari Yousaf Ahmadi has denied responsibility for the deadly attack.
The explosion at the mosque comes a day after an ISIL-claimed attack on the Iraqi embassy in Kabul killed two people.
Afghanistan’s national unity government said it strongly condemned the Herat attack, describing it in a statement as an “anti-Islam act”.
It also called “on the Muslim people of Afghanistan, as well as on the religious scholars, to stand united against the barbaric actions of the terrorists”.
President Ashraf Ghani said that “terrorists cannot create sectarian divisions among our people”.