Officers said about 20 attackers, armed with assault rifles, rocket-propelled grenades and mortars, set fire to the building and badly damaged it. The attack took place in the town of Miqdadiya, near Baquba and 65km (40 miles) north of Baghdad. Most of the dead were policemen. It was not clear how many inmates were freed.
The gunmen struck at dawn, arriving in civilian vehicles and attacking the government compound in the centre of town, which also included a court house and city council building. The raid lasted about an hour, before US helicopters helped drive the attackers away, security officials told the AFP news agency.
Sixteen people, most of them police but one thought to be a civilian security guard, were killed in the attack at the police station, while another two police died on their way to the scene when their vehicle hit a roadside bomb, according to one report. At least 13 others were reported injured. Accounts of insurgent losses varied, with reports of between one and 10 attackers killed. Miqdadiya lies in the heart of a mainly Sunni area that has seen a lot of insurgent activity.
While much of the recent focus has been on sectarian violence between Sunnis and Shias, the attack was a reminder that government forces and coalition troops are still being targeted by insurgents, says the BBC's Jim Muir in Baghdad.