Another 64 people were wounded, said Jelani Farhad, the Herat provincial spokesman.
The blasts took place during evening prayers.
ISIS took responsibility for the attack in a statement published Wednesday on several Telegram channels associated with the group.
The attack started when one suicide bomber began firing on worshippers inside the mosque before blowing himself up, said Abdul Ahad Walizada, spokesman for the police chief.
"Two attackers entered the mosque and started shooting and throwing grenades at people," Mohammad Adi, a survivor, told Reuters.
The second bomber was among the crowd of worshippers when he blew himself up, Walizada said.
Video from Reuters showed police inspecting bodies inside the mosque. Some people carried bodies in blankets, the video showed.
Officials fear the death toll could rise, because 10 of the wounded are in critical condition, said Dr. Arif Shahram, the director of Herat Regional Hospital.
In a statement, the US embassy in Afghanistan condemned the attack, describing it as "deplorable."
"We send our deepest condolences to the families and friends of those killed and injured," the statement said. "We commend the government and security forces ... for their response to this latest act of cowardly violence."