Militants killed about 50 men, women and children in Mirzawalang, a mainly Shiite village in Sayad district of northern Sar-e Pul province, on August 5 after overrunning a government-backed militia, according to officials and residents.
A spokesman for the Afghan National Army's northern military corps said troops had retaken the village following several days of intense fighting that left at least 50 insurgents dead.
"Our forces are in full control of the village and are searching for Taliban mines and booby traps," Nasratullah Jamshidi told AFP.
He told AFP that militants had suffered "heavy casualties". There has been no word on any casualties to Afghan forces.
More From This Section
Troops are expected to start searching for mass graves following claims from families and local officials that about 50, mostly-Shiite and Hazara, villagers were either shot or beheaded after Taliban and IS insurgents took Mirzawalang in a rare joint operation.
The Islamic State group claimed responsibility for killing 54 Shiites in Sar-e Pul in a statement released by its propaganda outlet Amaq late Monday.
Survivors fleeing the violence described nightmarish scenes, detailing how militants went from house to house, shooting villagers.
The insurgents also took a number of residents captive, but later released 235 hostages after elders and provincial officials struck a deal with the group.
Taliban and IS fighters have regularly clashed since the latter gained a foothold in the country in 2015 but security sources say they have teamed up to attack Afghan forces on a few occasions.
IS has carried out a number of deadly attacks on Shiites in the past year, providing a sectarian twist to the Afghan conflict.
A resurgent Taliban, whose ranks are mostly made up of Sunni Muslim ethnic Pashtuns, is at the height of its summer fighting season.