Ten others were wounded in the second attack in Jalalabad city in as many days, Nangarhar provincial governor spokesman Attaullah Khogyani said in a statement.
It is not clear how many government workers were trapped inside the building during the fierce gunbattle between security forces and militants that has now ended.
“So far 10 bodies have been recovered and taken to local hospitals. Ten people have also been wounded,” Khogyani said.
An AFP reporter at the scene confirmed seeing 10 bodies inside the compound. He also saw the remains of what officials said were the bodies of two attackers.
The sound of gunfire followed by a “big explosion” that shattered windows alerted Qari Samiullah to the fact that an attack was under way near his shop.
“I left my shop and ran when I heard a second explosion,” Samiullah told AFP. “Smoke came out of the building and all the people started to run away.”
Shir Mohammad was inside a nearby shop when the gunmen launched their attack.
“I heard gunfire which was followed by an explosion and then intense gunfire,” Mohammad told AFP.
A security guard employed by the education department branch was among the dead, Khogyani said. There was no immediate claim of responsibility for the raid.
Local teachers had been delivering exam results from their schools to the office when the gunmen attacked, provincial education department spokesman Asif Shinwari told AFP.
“Quite a few teachers are inside the building,” Shinwari added.
Jalalabad’s education department was also attacked by gunmen exactly a month ago. At least 10 people were wounded then. Nangarhar’s provincial capital has seen an uptick in violence in recent weeks, with the Islamic State group claiming most of the attacks.
On Tuesday, a suicide attack in the city killed at least 12 people and ignited a nearby petrol station, with witnesses describing screaming victims “swallowed” by flames.
The bomber was targeting Afghan security forces when he blew himself up. Ten civilians were among the dead.
IS claimed that attack via its Amaq propaganda agency.
More NATO troops
The series of high-casualty suicide bomb attacks in the province comes as US and Afghan forces continue offensive operations against the group.
One of the deadliest was on July 1 when a suicide bomber blew himself up among a group of Afghan Sikhs and Hindus in Jalalabad, killing at least 19 people.
While the Taliban is Afghanistan’s largest militant group, IS has a relatively small but potent presence, mainly in the north and east of the country.
Wednesday’s attack comes a day after President Ashraf Ghani flew to Brussels to attend a NATO summit where he will be hoping to get a greater commitment from members to the nearly 17-year conflict.
Currently, there are about 14,000 US troops in Afghanistan, providing the main component of the NATO mission there to support and train local forces.
British Prime Minister Theresa May is expected to pledge to send 440 extra troops to Afghanistan during the summit.
A recent ceasefire between Afghan security forces and the Taliban during the Islamic holiday Eid had raised hopes that an end to hostilities in the war-weary country was possible.
Since then, however, the Taliban has returned to the battlefield and IS, which was not involved in the truce, has continued to carry out deadly attacks.
Nangarhar has been under growing US pressure to crack down on extremist groups operating in the country.