The explosion also damaged a nearby municipal compound, giving insurgents a way into the complex where they fought Afghan security forces for hours, Sefatullah Samangani, the deputy governor of the province, said.
In the second attack late Sunday in north-eastern Badakhshan, seven policemen were killed in fighting with Taleban fighters, Mr Nik Mohammad, spokesman for the governor said.
Separately, at least 26 security forces were killed in coordinated attacks on Sunday in Kunduz province, also in the north, also claimed by the Taliban. He said there were 63 wounded but warned those were only initial figures and that the casualty toll could rise further.
The attack, which lasted for almost four hours, ended after security forces shot dead three armed men, the governor's spokesman, Mr Sediq Azizi, said.More news: $114000 Bid for Super Mario Bros
Mohammad Hashim Sarwari, deputy chief for the provincial council, said a suicide auto bomber targeted the NDS office and the blast was a signal for other Taliban fighters to storm the building.
Zabihullah Mujahid, a Taliban spokesman, said the armed group - who are active in the province and have recently stepped up attacks there - were behind the bombing.
Some 43 people, mostly civilians, were wounded, the director of the city's hospital, Gul Ahmad Quraishi, told AFP.
Afghanistan's Taliban has dismissed as "illogical" escalating domestic and foreign calls for the insurgent group to cease hostilities before the commencement of intra-Afghan peace negotiations.More news: McDonald’s offering free fries for National French Fry Day
The Taliban claimed the attack.
A peace deal signed by the Taliban and the United States in February calls for direct negotiations between the militant group and the Western-backed government in Kabul aimed at putting an end to the almost two-decade-old war in Afghanistan.
"It's a complex attack that started with a auto bomb", said Mohammad Sediq Azizi, a spokesman for the provincial government.More news: Betsy DeVos vows students will return to classes this fall