The Taliban targeted two military posts in western Afghanistan, killing 11 soldiers and setting off gun battles with the military, Afghan officials said on Wednesday.

In one attack, in western Farah province, the militants stormed a security post, killing nine troops and wounding four others. The attack took place on Tuesday night in Pusht Road district, said the governor's spokesman Mohammad Naser Mehri.

An intense, four-hour gun battle followed the attack and included the use of artillery against the army, Mehri said. Afghan warplanes were deployed and 17 Taliban fighters were killed, he claimed.

The second attack took place in neighboring Herat province, also on Tuesday night, and targeted an army post in Kushki Kuhna district, killing two soldiers and wounding five others, according to Najibullah Najibi, the military's spokesman in Herat.

The attack lasted several hours with the army succeeding in pushing back the Taliban, Najibi said. He claimed that the Taliban suffered “heavy casualties” but did not provide a figure.

There was no immediate comment from the Taliban on the attacks in Farah and Herat but insurgents have stepped attacks all across Afghanistan, with the last two weeks being particularly deadly for Afghan forces.

Last Thursday, a Taliban attack on a military compound left 43 soldiers dead in southern Kandahar province, a Taliban heartland. Meanwhile, Afghan officials also reported intense clashes on Monday and Tuesday in northern Jawzjan province between the Taliban and rival fighters from the militant Islamic State (IS) group affiliate that emerged in recent years in Afghanistan.

According to Faqir Mohammad Jawzjani, the provincial chief of police, the fighting left six IS militants and 42 Taliban fighters dead.

Jawzjani claimed the IS launched an attack on Taliban positions in several locations, capturing several areas and villages from the Taliban in two districts. He estimated that the number of IS fighters in the two districts Khush Tipa and Darzab is about 400.