KABUL, Afghanistan — Voting under threat of Taliban violence, Afghans across the country cast ballots in parliamentary elections held during one of the most fragile moments in 17 years of the war.

It was an election that was supposed to happen three years ago, delayed time and again by widening political schisms and worsening security. And where voting did go ahead on Saturday it did so under the shadow of a Taliban vow to punish those who took part. There was no voting at all in two critical provinces, and the government said ahead of the vote that only two-thirds of polling stations would open because of security issues.

The insurgents carried through on their threat, but security forces prevented the dramatic attacks that many feared. Still, officials said there was widespread violence across the country, with the Taliban attacking districts and polling centers, firing mortar shells and exploding bombs in cities.

A rough tally from security and health officials after polls closed showed that at least 78 people, including 28 members of the security forces, were killed and least 470, mostly civilians, were wounded in smaller attacks targeting dozens of districts. In Kabul alone, more than a dozen explosions were reported by officials.