Many more were wounded in the attack in Baquba - the second targeting Iraq's security forces in two days.
On Tuesday, a suicide bomber killed some 60 people at a police recruitment centre in Tikrit, the hometown of former Iraqi leader Saddam Hussein.
Violence in Iraq has ebbed in recent years, but deadly attacks persist.
Both Baquba - 65km (40 miles) north-east of Baghdad - and Tikrit are within what is known as the Sunni Triangle, a stronghold of Iraq's insurgency.
Most of those killed in Wednesday morning's attack were police, officials said.
A gunman stepped out of the ambulance, opened fire on guards at the entrance of the city's special security police centre, and then the vehicle was driven into the compound and detonated, reports said.
More than 60 injuries were reported, and more people are said to be buried under rubble after the explosion caused a building to collapse.
"There are more bodies buried in the ruins," a spokeswoman for Diyala's governor told Reuters news agency.
Iraqi police and army recruiting centres are often targeted by suicide bombers.
Overall violence in Iraq has fallen sharply since the height of the sectarian killings of 2006-07, but shootings and bombings remain a daily occurrence.
US forces formally ended their combat operations last August, ahead of a planned full withdrawal later this year.