Afghan forces have recaptured a remote village where fighters from the Islamic State of Iraq and the Levant (ISIL, also known as ISIS) group massacred dozens of civilians earlier this month, officials said.

A spokesman for the Afghan army said on Tuesday that government troops retook Mirzawalang village in northern Sar-e Pul province after several days of intense clashes with Taliban fighters.

"Our forces are in full control of the village and are searching for Taliban mines and booby traps," Nasratullah Jamshidi told the AFP news agency.

Dawlat Waziri, a spokesman for the Afghan defence ministry, said its forces had "pushed the Taliban out of the village" on Monday afternoon.

READ MORE: Father of robotics team member killed in Herat attack

Troops are due to start searching for mass graves following claims by families and local officials that about 50 villagers, including women and children, were either shot or beheaded on August 5.

ISIL on Tuesday claimed responsibility for the killings, but officials said it was "a joint operation by ISIL and Taliban fighters".

"They had recruited forces from other provinces of the country and attacked Mirzawalang village," Zabihullah Amani, spokesman for the provincial governor, said after the attack.

The Taliban earlier claimed that its fighters had captured the village but said they did so alone. It also denied allegations that they had killed civilians.

Survivors fleeing the violence described the horror, detailing how fighters went from house to house shooting villagers.

"Me, my brother Ghulam and my sister-in-law left our home to escape the horror that was happening in the village," Sakhi, a resident of Mirzawalang, told Al Jazeera, adding: "When we reached the highway, the militants blocking it asked us to get out of the car and started hitting us."

"They beheaded my brother and the others in the car, who were with us trying to escape.

"I grabbed my sister-in-law's hand and ran as fast as I could. They started firing, but we managed to escape," Sakhi said, describing how he also witnessed women and children being beheaded.

"I can't cope with the horror and pain...we've been through hell."

Over the past year, ISIL has carried out a number of deadly attacks on civilians, particularly the Shia community in Afghanistan.

This month two suicide bombers killed more than 33 worshippers at a mosque in Afghanistan's western city of Herat, in an attack claimed by the group.