Insurgents also released prisoners from the police headquarters in Muqdadiya, northeast of Baghdad.
Authorities said at least 14 policemen were killed at the station, and two more bodies were found at the courthouse after security guards at the building came under attack.
Two more policemen were killed by a roadside bomb as their unit rushed from the nearby town of Baquba to help out.
A large number of insurgents arrived in cars and pickup trucks and attacked the government compound in the centre of town with machine guns and rocket-propelled grenades.
The raid lasted about an hour with rebels, who lost three men, only withdrawing when Iraqi military reinforcements were rushed in.
US helicopters pursued rebels and attacked them as they escaped into orchards on the outskirts of the town, some 100 kilometres (70 miles) from Baghdad, Iraqi security officials said.
There was no immediate confirmation from the US military.
The attack comes as the third anniversary of the US invasion of Iraq was marked with protests around the world and yet more violence in Iraq.
At least 38 people were killed earlier by insurgents and sectarian gangs, according to Iraqi police reports.
Police said they found the bodies of at least 15 more people, including that of a 13-year-old girl - dumped in and around Baghdad.
There has been an upward spiral of violence since the February 22 bombing of a Shiite Muslim shrine in Samarra, with some putting the death toll at 992 in the past month.
At least three civilians were killed and 23 others injured when a bomb exploded in a coffee shop in northern Baghdad, about the same time as two oil engineers were killed leaving work at the Beiji refinery, north of the capital.
In south-east Baghdad on Monday night, a roadside bomb blew up a minibus, killing four people returning from a pilgrimage in Karbala.
Nevertheless, US President George W Bush claimed in a speech in Ohio that victory would come eventually.
"Some Americans have had their confidence shaken," said Mr Bush, in one of a series of speeches aimed at shoring up public opinion of the war in Iraq.
"I understand people being disheartened when they turn on TV screens and see the loss of innocent life," Bush said.
"Nobody likes beheadings (or) ... when innocent children get car-bombed."
But he reiterated that US forces would not retreat from intimidation and violence.
