Gunmen dressed in military uniforms have stormed the office of the attorney general in the northern Afghan city of Mazar-e-Sharif, killing at least five people and injuring 25.
Witnesses told the BBC they saw four attackers enter the office, followed by heavy gunfire and several explosions.
Afghanistan’s interior ministry said three gunmen had been killed, leaving one or two still inside the building.
A spokesman for the Taliban said the group had carried out the attack.
Police said they had rescued the attorney general, whose office is just 200m (650ft) from the office of the governor of Balkh province.
The governor’s aide told the BBC that the governor, Atta Muhammad Nur, was at home at the time of the attack but was taken to his office, where he is monitoring the situation.
The area has been surrounded by the Afghan National Security Forces.
At the scene: Tahir Qadiry, journalist, Mazar-e-Sharif
I can still hear shooting and grenade explosions from our home, about 500m from the scene. I had only just driven my wife and daughter away from where the attack took place when the shooting began.
Many of the roads around the scene are now closed and helicopters are hovering overhead. Schools were also closed and parents took their children home.
People here look shaken and scared. The attack has shattered many peaceful months in Balkh.
Officials tell me that Balkh governor Atta Muhammad Nur is close to the scene and directing the security forces himself.
Noor Mohammad Faiz, chief doctor at the Balkh Provincial Hospital, confirmed to the BBC that five people had been killed in the attack and 25 injured, three critically.
In a statement seen by the BBC, Taliban spokesman Zabihullah Mujahid said: “Breaking News: This noon suicide [attackers] stormed office of the attorney and appeal court of Balkh province. Heavy casualties for enemy, battle continues.”
The Taliban has targeted Afghanistan’s legal system in the past. In June 2013, the group detonated a car bomb in front of the compound of Afghanistan’s Supreme Court, killing 17 and wounding 39.
And in December of 2014, Atiqullah Raufi, the chief of the secretariat of Afghanistan’s Supreme Court, was assassinated by Taliban gunmen in the west of Kabul.
The attack in Mazar-e-Sharif comes a day after an American soldier was killed in a fire fight between US and Afghan troops in eastern Afghanistan.