Two rival groups of Taliban and the ISIL militants made alliance and jointly attacked Mirza Olang village in Sayyad district on Thursday, and captured it on Saturday, the day when the killing took place, spokesman Zabiullah Amani told Xinhua.
"The militants overran the village on Saturday after two days of intense clashes with Afghan Local Police and allied local tribal militias, known as local uprising groups. They cowardly and indiscriminately shot dead the villagers together with local forces after capturing the area," he said.
Those among the killed were more than 20 civilians, including women and children, the source added.
Some victims were shot dead while several others were beheaded and most of the victims were Shiite Muslims from minority Hazara ethnic.
Taliban and the IS group have frequently been fighting in eastern and northern regions as well as in the restive south to gain territory.
The mountainous province has been the scene of heavy clashes over the past two years.
The Taliban militants have claimed that the attack was launched by their fighters and the killed were all local police and government-backed militiamen.
Afghan President Ashraf Ghani and Chief Executive Abdullah Abdullah strongly condemned the killings on their Twitter accounts.