The ongoing assault in Mazar-i-Sharif city comes just before the start of the Taliban's traditional spring offensive, set to be the first fighting season when Afghan security forces battle insurgents without full NATO support.
Explosions rang out as assailants wearing suicide vests lobbed grenades and exchanged gunfire with Afghan security forces, setting ablaze one of the buildings in the compound, according to an AFP reporter at the scene.
"Police reinforcements reached the site of the attack and immediately launched operations against the insurgents. The clean up operations are underway."
At least three policemen were killed, the acting governor of the affected Balkh province, Atta Mohammad Noor, said in a statement.
More From This Section
Thirty-one wounded people, some in critical condition, were brought to the local public hospital.
"Police, prosecutors, court staff, women and children were among those wounded," Noor Mohammad Faiz, a senior doctor at the hospital, told AFP.
Nearly five hours after the attack started, reports of blood shortages in hospitals emerged, with urgent appeals for donors circulating on social media.
The Taliban claimed responsibility for Thursday's assault, which underscores Afghanistan's precarious security situation as US-led foreign troops pull back from the frontlines after a 13-year war against the Taliban.
"Our mujahideen have carried out a martyrdom attack... In Mazar-i-Sharif city," Taliban spokesman Zabihullah Mujahid told AFP by telephone.
"Heavy fighting is going on between our mujahideen and Afghan forces in the area.