BAGHDAD - Seven children were killed and 42 wounded in a Shi'ite district of Baghdad Monday when a bomb exploded outside a school, police said.

The explosion occurred in Baghdad's Sadr City slum as primary school pupils aged between 6 and 12 were leaving at the end of the school day, an army officer said.

It was not clear if the bomb had been set to go off at that time or was inadvertently detonated after a rubbish heap was set on fire, the officer said. The blast made a crater 2 meters (6 feet) deep and 5 meters (16 feet) wide, he added.

The explosion shattered windows and scattered textbooks across classroom floors that were spattered with blood.

The site of the bombing was a complex of buildings that includes another primary school and a school for children aged between 13 and 15, officials said.

Overall violence in Iraq has fallen dramatically in the past 18 months. Civilian deaths last month totaled 88, their lowest since the 2003 U.S. invasion, according to government figures.

A bomb at a busy market in Sadr City, a poor area seen as a stronghold of Shi'ite militants, killed 72 people and wounded 127 in June.

Earlier Monday, unidentified gunmen shot dead five Sunni neighborhood guards manning a checkpoint on the northern outskirts of Baghdad, police said. The guards were part of a Sahwa, a formerly U.S.- and now government-backed force.

(Writing by Ayla Jean Yackley; Editing by Andrew Dobbie)