Suicide bombers disguised as soldiers have stormed an court in western Afghanistan, killing at least 46 people in an attempt to free Taliban fighters standing trial, officials say.
At least nine fighters were also killed in Wednesday's attack, which occurred in Farah, the main town of Farah province.
It was not immediately clear whether the accused men had escaped the court complex, although a hospital doctor said one prisoner was among those being treated for injuries.
"The attack is over, but the casualties have unfortunately risen," Mohammad Akram Khpalwak, governor of Farah province, told the AFP news agency.
"In total, 34 civilians and 12 [Afghan] security forces have been killed in the attack. We have also discovered the bodies of eight attackers, more than 100 people have also been injured."
The multiple bomb-and-gun assault will raise further questions about the Afghans' ability to secure the country as NATO reduces its combat mission by the end of next year.
The assault came as Afghan President Hamid Karzai, speaking to Al Jazeera in Qatar, said he remained open to talks with the Taliban, but that he wanted to secure the progress his government has made.
Wednesday's death toll was the highest in Afghanistan from a single attack since a Shia Muslim shrine was bombed in Kabul in December 2011, killing 80 people.
| Our complete Afghanistan coverage
The Taliban claimed responsibility for the Farah attack.
"Our fighters attacked several government buildings in Farah according to their planned tactic. They conducted the attack with small arms and grenades," the group said on its website.
"The fighting happened after information that Karzai's administration wanted to try several fighters in a cruel way in this court."
Taliban fighters frequently target government compounds equipped with suicide vests, rockets and machine-guns.
"At around 8am [03:30 GMT] five attackers riding in two military-style vehicles drove to the provincial court building, one [vehicle] detonated at the gate and three attackers entered the building," Agha Noor Kentos, police chief of Farah, told AFP.
Wounded being treated
Wakil Ahmad, a doctor at Farah hospital, said medics were treating scores of wounded including two judges and one court prisoner.
The governor's compound was around 200 metres away from the scene of attack, an AFP reporter said.
Last year armed men dressed in Afghan police uniforms and wearing suicide vests stormed a government compound in Farah and killed seven people.
In November a roadside bomb planted by Taliban fighters killed 17 civilians, mostly women and children, on their way to a wedding party in Farah.
Al Jazeera's Jennifer Glasse, reporting from Kabul, recalled
meeting a former Taliban commander last week, when there was an attack on a police training headquarters, before Karzai travelled to Doha for talks on the possible opening of a Taliban office in the Qatari capital.
She said the Taliban commander told her there was still a war going on and that until the Taliban's demands were met, among which was the release of Taliban prisoners, attacks such as the one on the police centre would continue in Afghanistan.
The Taliban insurgency has raged since a 2001 US-led invasion put an end to its five-year rule over large parts of Afghanistan.
The group has increasingly widened its attacks outside its main power bases in the east and south, where NATO forces have focused their attention, to other areas such as Farah which borders Iran.
NATO combat troops are due to pull out of Afghanistan by the end of 2014, leaving responsibility for security to Afghan security forces.
However, there are fears that the violence will increase with their departure.