KABUL, Afghanistan — As a crowd of Afghans lined up outside a voter registration center in Kabul on Sunday, a suicide bomber blew himself up, killing 57 people in the deadliest of a spate of attacks on Afghanistan’s upcoming elections, officials said.

Six people were also killed when a vehicle struck a roadside bomb near a voter registration center in the northern province of Baghlan, the fifth attack in a week on the election process, Afghan media reported.

The Kabul attack, in the western area of the capital in a neighborhood heavily populated with members of the Hazara ethnic group, targeted a compound where government statistics officials were distributing national identification cards.

The death toll climbed steadily throughout the day, and by nightfall it stood at 57 people dead and 119 wounded, said Wahidullah Majrooh, spokesman for the Afghan public health ministry.

At least five of the dead were children, believed to have been students at a nearby high school.

Witnesses said only two police officers were guarding the center, adding to fears that Afghan security forces were ill-prepared to stop insurgent attacks on parliamentary elections scheduled for October.

The bomber detonated his vest in the crowd before he could be searched by police, said Hashmat Stanikzai, a Kabul police spokesman. He could not confirm how many officers were posted at the center.

Islamic State claimed responsibility for the attack via its Amaq news agency, saying its target was Shiite Muslims. Most Hazaras are Shiite. The Sunni extremist group has claimed several high-profile bombings against Shiites in Afghanistan, including one at a mosque last October in which more than 50 people were killed.

A U.S.-led campaign of ground and air operations has reduced Islamic State’s presence in Afghanistan to several hundred fighters. But they have continued to claim devastating assaults on the heart of Kabul, illustrating the inability of Afghan forces to secure prominent public places.

Witnesses had complained to police a day before the bombing that there was far too little security at the registration center, which is in a residential area. Haji Zaman, a tribal elder, said more than 100 people were waiting in line outside the compound Saturday with just two police officers guarding the center.

“I argued with policemen and some more people came to support me, saying there’s no security outside the compound and people shouldn’t gather there,” Zaman said. He said he called the head of the center and told him to shut it down because civilians could be at risk.

When the center opened a week ago, as President Ashraf Ghani began a voter registration drive, Zaman said that authorities had promised to erect barriers and station about 60 security officers around the center. They never did, he said.

On Sunday, Zaman was standing near the line when a woman approached him holding her photo, asking for his help in registering to vote. As he spoke with her, the blast ripped through the air, throwing them to the ground.

Zaman escaped unharmed, but the woman was wounded. Blood-spattered bodies lay everywhere, he said; bits of flesh were caught in the trees.

Jawad, a 34-year-old who uses only one name, said the explosion left his ears ringing for several minutes. He helped get bodies into ambulances but said that no additional security forces arrived until most of the victims had been taken to hospitals.

Hours after the blast, he stood outside the center carrying a white plastic bag that he had salvaged from the site. Inside were the ID papers of someone he had never met.

“The government has been calling on people to get registered and vote, and now I’m holding an ID and a voting card of a victim fallen in blood,” Jawad said. “Is this the way that the government promises to secure the voting process?”