A Taliban attack on a government compound in Afghanistan has killed up to 12 people and wounded 150 after a massive truck bomb triggered three hours of fighting.

About 20 insurgents armed with machine guns and grenade launchers were also killed during the attack on the intelligence agency base in Ghazni province, one of the most volatile regions of Afghanistan.

The attack underlined growing insecurity in the country, which is beset by a political crisis over disputed election results at the same time that US-led NATO combat troops wind down their war against the Taliban.

The group claimed responsibility for the attack through a recognised Twitter account.

The blast at the entrance of the compound sent broken glass raining down on civilians in the city before security forces fought an intense battle with the attackers and finally regained control.

"After a three-hour gun battle, the security forces killed all 19 attackers," Assadullah Ensafi, deputy police chief of Ghazni said.

"Three police were also killed. Eight NDS (National Directorate of Security) intelligence personnel and six police were wounded.

"The truck bomb was very strong, it broke windows of houses and shops around the building."

About 60 people, including many civilians, were treated at Ghazni hospital, Dr Memat, who only uses one name, told AFP.

He said 15 people were in critical condition.

The disputed election has emboldened the Taliban, with fresh offensives launched in the south and east, while several provinces close to the capital Kabul have suffered worsening unrest.

The two rival presidential candidates, Ashraf Ghani and Abdullah Abdullah, both claim they won the fraud-tainted election in June.