BAGHDAD — At least 45 people were killed and dozens more ­injured when a bomb detonated Thursday evening at a popular car market in southwestern Baghdad, the deadliest in a series of recent attacks in the Iraqi capital blamed on the Islamic State ­militant group, the Interior ­Ministry said.

A ministry spokesman said the bomb was placed in a parked car at the market in the Bayaa neighborhood, between Baghdad International Airport and the Tigris River. The Islamic State asserted responsibility in a brief statement circulated on social media.

The attack was at least the third bombing in the capital in as many days, and it appeared to be aimed at diverting the ­government as it prepares an offensive to drive the Islamic State from the northern city of Mosul, the militants’ last major stronghold in Iraq.

The Iraqi government has spent years and untold sums ­trying to secure Baghdad, using checkpoints, blast walls and ­other measures, but militants have consistently found ways through, carrying out small-scale attacks with an alarming frequency and mass killings at regular intervals. In November, an explosion killed at least 70 people, most of them Iranian pilgrims, at a gas station south of Baghdad, in an attack claimed by the Islamic State.

Burnt vehicles at the scene of the blast. (Ahmad Mousa/AFP/Getty Images)

Mushtaq Talib, a 28-year-old dentist who lives about 2 1/2 miles from the car market, said the explosion shook his house. The market was crowded, as is typical on Thursdays and Fridays, with people visiting used-car shops and driving their own vehicles to the area, hoping for a sale.

Soon after the explosion, Talib rushed to the scene, which he said had been secured by a single checkpoint before the attack, staffed by police officers.

“It was horrible,” he said. “Dead bodies and body parts everywhere, they were all ­civilians.”

Cars not disabled by the blast were used to ferry the wounded to the hospital, as others waited for ambulances to arrive.

Videos of the bombing that circulated on the Internet showed large-scale damage and terrible scenes: a line of white minibuses in flames, firefighters stumbling from one fire to the next and bodies everywhere, ­disfigured on the ground or ­bundled into a crude wheel­barrow with someone’s arm dangling over the side.

“These are the Iraqi people,” a man, wailing, can be heard saying over and over in one of the video clips. In another video, a boy shouted that his father was lying under his food cart. It was not clear whether the man was alive.

The string of attacks comes as the militant group is trying to stave off defeat in Mosul. Iraqi military forces, backed by the United States, have secured the eastern party of the city and are expected to advance on western Mosul in the coming days. The remainder of the battle may turn out to be more grueling than its initial phase, which lasted nearly four months. Iraqi forces will be fighting in streets too narrow for armored vehicles to pass, in neighborhoods densely packed with civilians, against militants who may regard the fight for the strategic Iraqi city as a last stand.