Taliban militants disguised as Afghan soldiers have attacked a government compound.

It was a failed attempt to free more than a dozen prisoners being transferred to court proceedings in the west of the country.

At least 53 people, including nine attackers, have been killed.

At least 72 people were wounded in the attack, including 12 security forces and 60 civilians.

According to provincial police, the attackers, who were wearing suicide vests, drove into the centre of Farah in Afghan national army vehicles that allowed them to bypass checkpoints.

Two of the attackers blew themselves up inside one of the vehicles, while four others jumped out of the second and ran toward the courthouse and prosecutor's office, according to reports.

Guards opened fire, killing one of the attackers, while the other three fled to nearby buildings and engaged in a battle that left civil servants and government officials hiding in their offices.

Farah province, which is bordered by Iran to the west and Afghanistan's volatile Helmand province to the east, has seen an increase in attacks against the local government in recent months as militants seek to disrupt efforts to stabilise the area.

The persistent violence has undermined confidence in Afghan President Hamid Karzai's government as it tries to take over its own security ahead of the withdrawal of international combat forces by the end of 2014.