The Taliban released 235 hostages from a remote village in northern Afghanistan where it allegedly massacred as many as 50 mostly Shi'ite civilians in a rare joint assault with Islamic State insurgents, officials said on August 8.

"This evening, 235 people, including women and children, were released from Mirza Olang as a result of mediation by the local elders and provincial officials," Zabihullah Amani, a spokesman for the provincial governor, told AFP.

"They have been safely evacuated to Sar-e Pul city, but there are still an unknown number of people being kept hostage there," he said.

An Afghan security source told AFP there were still around 100 people being held hostage in Mirza Olang, situated in the Sayad district of Sar-e Pul Province, after insurgents captured it over the weekend.

Taliban and IS fighters working together in a rare joint operation killed around 50 men, women, and children in the mainly Shi'ite village on August 5 after overrunning a government-backed militia in a two-day battle, according to local officials, who also said they took about 150 families captive.

The Taliban denies it was a joint operation, saying a group under one of its commanders carried out the attack.

However, local villagers reported seeing fighters carrying both the white banner of the Taliban and the black banner of the Islamic State extremist group.

The Taliban has for years fought to install strict Islamic law and drive foreign forces out of Afghanistan, and it fiercely opposed IS's local affiliate when its first appeared in Afghanistan in 2015.

Any sign the two groups are now joining forces would alarm Western governments concerned about Afghanistan once again becoming a base for militant groups aiming to strike foreign targets.

The Al-Qaeda militant group worked with the Taliban and made Afghanistan its home base before the September 11, 2001, terrorist attacks. IS started out as an offshoot of Al-Qaeda's Iraqi affiliate before the two extremist groups became rivals.

The slaughter of civilians, most of them Shi'ites, has been a trademark of IS and its extremist brand of Sunni Islam. The majority of those killed in Mirza Olang were shot or beheaded, Amani told AFP.

Afghan Defense Ministry spokesman Dawlat Waziri told AFP that 34 civilians were known to have been killed.

The discrepancy in the number of casualties highlights the difficulty of verifying information from poor, mountainous areas of Afghanistan made inaccessible by fighting and poor communications.

"Despite the efforts of elders, the bodies of the victims have not been recovered," Zaher Wahdat, the provincial governor, told Tolo News, an Afghan television channel.

"Two hundred and thirty-five hostages have been released. They are so shocked they can't even speak to tell us about any more other hostages," he said.

Amani, the provincial spokesman, said that dozens of Taliban and IS group fighters, under the command of a local Taliban commander who he claimed pledged allegiance to IS, launched a coordinated attack on the area on August 3.

Some 330 families escaped the area after warnings from the Taliban, but most of the civilians killed in the incident died while trying to leave, Reuters reported.

The insurgents defeated the Afghan local police after a 48-hour battle before massacring civilians, Amani said.

The Taliban confirmed capturing Mirza Olang but said it did so alone. It also denied allegations the insurgents killed civilians.

Taliban and IS fighters have regularly clashed in Afghanistan over the past two years, but security sources say they have teamed up in the past to strike Afghan forces in certain areas.

The release of hostages came after Afghan special forces amassed and launched an operation to retake the village.

"Commando forces have been deployed to the area, air strikes are being carried out as we speak, and commanders on the ground are busy planning the recapture of the valley," said Waziri, the Defense Ministry spokesman, promising that "the terrorists will pay for their crimes."

Sediq Sediqi, a spokesman for the Afghan government, told AFP it was difficult to know how many civilians were killed or captured but said "President Ashraf Ghani has instructed everyone to do everything to safeguard those people."

Ghani, whose government has recently been besieged by protests from Afghan civilians angry that the government is not protecting them from terrorist attacks, has vowed "revenge" for the attack.