Updated

BAGHDAD -- Four bombs ripped through Shiite neighborhoods in Baghdad Thursday evening, killing at least 40 people in the worst violence the capital has seen in months, Iraqi officials said. An American civilian contractor also died in a separate attack.

The violence underscored the fragile nature of the security gains in Iraq at a time when American forces are preparing to withdraw by the end of this year and the challenges facing the State Department personnel and American contractors who would continue on after the U.S. military is gone.

The first three bombs went off in quick succession in a southwestern Baghdad neighborhood shortly after 7 p.m. One targeted a Shiite mosque, another exploded just outside a popular market, while the third went off inside the market where people were doing their evening shopping ahead of the Muslim weekend, Iraqi police officials said.

The officials said 82 others were injured in the three blasts. An official from Baghdad's Yarmouk hospital confirmed the figures.

An Iraqi resident, Jabir Ali, said he was about 200 yards away when one of the bombs went off near a barber shop where his cousin works.

"I saw many people killed and injured. I went to see my cousin. The glass at his shop was broken and he was injured in his head, chest and hand by the glass," said Ali, who drove his cousin to the hospital.

About an hour later, a parked car bomb targeting a police patrol killed six people, including one policeman and five bystanders in a different neighborhood in southwestern Baghdad, said hospital officials.

There was no immediate claim of responsibility, but Sunni extremists such as Al Qaeda in Iraq generally tend to target Shiite mosques and neighborhoods and Iraqi security forces.

The American civilian killed earlier Thursday was working for an agency assisting the U.S. government, said David J. Ranz, the spokesman for the U.S. Embassy in Baghdad.

"An American civilian working with an implementing partner of the United States Agency for International Development in Iraq was killed in a terrorist attack today in Baghdad. Three additional civilians were wounded in the attack, including one American citizen," he said.

The name of the victim was being withheld until relatives are notified, Ranz said.

He gave no information about where or when the attack took place.

Iraqi police officials in eastern Baghdad said a bomb exploded near foreign security company vehicles traveling through eastern Baghdad early Thursday afternoon, killing one foreigner in the convoy and injuring three other people.

The officials all spoke on condition of anonymity because they were not authorized to speak to reporters.

Earlier this week, a convoy carrying French Embassy staff was targeted by a roadside bomb in the Karradah neighborhood. No one was killed in that incident.