The attack took place in Aybak, the capital of the Samangan province. Sediq Azizi, a spokesman for the provincial governor, said another 63 people were wounded in the attack and the ensuing clashes.
A suicide bomber struck the compound, followed by two insurgents who opened fire. Both were killed in the gun battle, Azizi said. The blast from the initial bombing could be heard miles (kilometres) away and damaged several nearby buildings.
Abdul Khalil Musadiq, a provincial hospital chief, said many of those wounded were civilians, including children.
The Taliban claimed the attack. The insurgents have continued to regularly target Afghan security forces despite signing a peace agreement with the US in February that was intended to pave the way for an end to decades of war.
On Sunday, the Taliban attacked checkpoints in the northern Kunduz province, killing at least 14 Afghan security forces, according to Esmatullah Muradi, a spokesman for the provincial governor.
The Taliban said they were behind the attacks but claimed government forces fired mortar shells in response, hitting civilian homes — a claimed dismissed by the Defence Ministry.
The Taliban and government forces have been trading blame over a recent surge in violence across Afghanistan — even as efforts continue to try and bring about the start of direct peace talks between the government and the insurgents.
President Ashraf Ghani condemned the attack in Samangan and accused the Taliban of trying to strengthen their hand ahead of any negotiations.
The Taliban accuse government forces of targeting them in their homes, with their families bearing the brunt of those operations. The government says the insurgents continue to attack security forces and civilians.
Be Part of Quality Journalism
Quality journalism takes a lot of time, money and hard work to produce and despite all the hardships we still do it. Our reporters and editors are working overtime in Kashmir and beyond to cover what you care about, break big stories, and expose injustices that can change lives. Today more people are reading Kashmir Observer than ever, but only a handful are paying while advertising revenues are falling fast.