Gunmen in military uniform broke into the city council and court house in Samarra in northern Iraq on Tuesday, holding the facility for four hours until police and army stormed the compound, the mayor and police officials said.
Four policemen were killed in the fighting, along with three civilians who were visiting the city council and were shot when Iraqi security forces opened fire to retake the site, a senior police officer said.
A further 47 people were wounded, including 30 soldiers and policemen, according to officials at the Samarra hospital. The deputy head of the city council, Ammar Ahmed, and a second member were wounded.
"The Iraqi police and army managed to clear the building," Samarra Mayor Mahmoud Khalaf said. "The situation is under control."
Three fighters, who had holed up in the city council building, detonated their suicide vests rather than surrender, Khalaf said. The three had stormed the area after a fourth detonated his vest at the entrance of the compound, which is sealed off with blast walls, Police Lieutenant Dhafir Ahmed said.
Two policemen had been racing to help when a parked car bomb blew up their vehicle about 200 meters (yards) from the site. Gunmen had taken the city council's second floor and its roof.
Casualties might have been greater but many staff were attending a meeting across town with the mayor and governor of Salahuddin province, two police officials said. Samarra has long been troubled by unrest. Sunni militant groups have regularly attacked local Sunni government officials along with the Iraqi army and police.
In late December, gunmen seized the state television channel in Tikrit, the capital of Salahuddin province. The fighters employed similar tactics to those used in Samarra on Tuesday.
Sunni Islamist insurgents have been regaining ground in Iraq over the past year and in recent weeks overran several towns. Last year was Iraq's bloodiest since sectarian violence began to abate in 2008, with nearly 8,000 civilians killed. More than 700 people died in violence in Iraq in February, the United Nations said last week.
Iraqi Prime Minister Nuri al-Maliki says the upsurge is a spillover from the civil war in neighbouring Syria but critics say his own policies are as much to blame for reviving an insurgency that climaxed in 2006-07.
Many in Iraq's once-dominant Sunni Muslim minority feel they have been sidelined in the Shi'ite-led political order that took shape after the U.S.-led invasion in 2003 that toppled Sunni dictator Saddam Hussein.
Sunni militants have shown themselves adept at breaking into state compounds in recent years. Their targets have included attacks on the Iraqi central bank in the heart of Baghdad in 2010 and the freeing of more than 500 prisoners from Abu Ghraib prison west of Baghdad last summer.
Iraq's current security crisis started last April after army and police shot dead more than 50 demonstrators at a Sunni protest site in Hawija in northern Iraq.
That event was used as an excuse by al Qaeda inspired militants to carry out a campaign of suicide bombings in Shiite parts of the country and other attacks.
Since January, after Maliki's government arrested a Sunni lawmaker and cleared a protest camp in the Sunni city of Ramadi in western Anbar province, the army has been battling angry Sunni tribes and al Qaeda-linked groups for control of both Ramadi and nearby Falluja.
The concentration of troops in western Iraq has opened up space for armed groups to carry out attacks in other parts of the country, including Baghdad and northern Salahuddin and Nineveh provinces. Violence is nowhere near the levels seen in 2006 and 2007, but people once more fear the country could fall apart.