Militants involved in the attack in Diyala's provincial capital of Baquba exchanged fire with Iraqi security forces, holding them at bay, and took hostages in the siege that lasted nearly three hours.
The gunbattle ended when Iraqi security forces took control of the building with US military assistance.
News that makes sense
Your trusted source for staying up-to-date with the world around you. Get free daily news updates and analysis, straight to your inbox.
Large numbers of Iraqi police and soldiers were deployed to the scene, while military helicopters hovered overhead and periodically fired on the building during the siege, an AFP reporter said.
The attack, in which dozens of people were wounded, raises concerns over the capabilities of Iraq's forces to maintain stability in the country on their own, just months before US soldiers must leave under a bilateral security pact.
Major Angela Funaro, a US military spokeswoman, said the army helped with the initial search of the government building, aided in forming a security perimeter, and used American helicopters to provide aerial information.
She added that several "tactical US vehicles" were in the area as part of a routine convoy, and noted that American helicopters "did not fire upon individuals or targets on the ground."
Tuesday's attack saw insurgents set off two car bombs against the perimeter wall of the provincial government compound at about 9:30 am (0630 GMT), before the militants stormed it, and set off twin suicide blasts inside the building itself.
Iraqi security forces then surrounded the compound and imposed a city-wide curfew, with security officials only reporting the mayhem over at around 12:20 pm (0920 GMT).
An official in Diyala's security command centre said seven people were killed and 35 wounded, while an interior ministry official in Baghdad put the toll at eight killed and 27 wounded.
Among the dead were four policemen, according to Ahmed Alwan, a doctor at Baquba's main hospital.
