They huddled in the rain under plastic sheeting. They ignored death threats and sporadic firefights. After weeks of tension and violence, men and women turned out here Saturday in larger numbers than expected to choose a new president to lead them into the post-American era in Afghanistan.

Conducted under armed guard, the country’s third presidential election since the overthrow of the Taliban in 2001 unfolded without the large-scale attacks or major disruptions that many Afghans had feared, although scores of minor attacks were reported. As the process moves to a vote count that could take weeks and, potentially, lead to a second-round runoff, voters and observers expressed relief that the day had ended in relative peace.

“The turnout was far beyond what we had imagined,” said Zia ul-Haq Amarkhail, a senior Afghan election official, as polls closed.

The election brings Afghanistan a step closer to the first peaceful and democratic transfer of power in the history of the country, where presidents and kings more often leave dead or deposed. Whoever moves into the presidential palace, though, will face a thriving Taliban insurgency, deeply ingrained government corruption and the need to negotiate a future relationship with the departing United States, which has propped up and paid for the Afghan government and its soldiers and police for a dozen years.

The vote also marks the first time since Sept. 11, 2001, that the incoming leader will not be Hamid Karzai.

The Afghan presidential campaign has narrowed to a field of eight men, who are running to succeed Hamid Karzai.

The last time around, in the summer of 2009, when Karzai prevailed in a vote discredited by widespread fraud and low turnout, the day also seemed at first to have gone well. It took some time, even after complaints started pouring in, to understand that the scale of the ballot-stuffing and violence had been large enough to change the outcome. The most obvious early problems Saturday were that some polling stations appeared to run out of ballots and that in rural areas where the insurgency is strong, many people were too frightened to vote.

Election Day dawned cold and drizzly in Kabul. Residents made their way to ballot boxes in schools and mosques, navigating desolate streets guarded by thousands of police officers and soldiers. In some locations, polls opened as much as an hour late, but voters soon assembled in long, orderly lines to drop their ballots in plastic tubs and then dip their fingers in purple ink.

Afghans who have lived through decades of war spoke of their hopes for peace, better schools, more jobs. Using a side entrance reserved for female voters, Zakia Raoufi, a 45-year-old housewife, voted at the same school her son graduated from three years ago, and Karzai years before that. It was the first time in three days that she had left her house, she said, noting the near-daily bombings in Kabul ahead of the election.

“I was wondering whether I will come back home alive or not,” she said.

Her son had studied computers and learned English at Habibia High School, but the family had no connections in the government elite and no money to pay bribes for employment, so he moved to Iran, where he works as a tailor.

“So this election means a lot to me,” she said. “What I’m hoping for from the next president is someone to stop the bloodshed in this country, to provide us peace and stability and education and opportunities for our children.”

Before the vote, polling suggested a tight race. Of the eight candidates, Karzai’s inner circle pushed Zalmay Rassoul, a French-educated physician and former national security adviser and foreign minister. But Abdullah Abdullah, another former foreign minister, and Ashraf Ghani, a former finance minister and World Bank official, attracted large crowds at their rallies. If no one wins more than 50 percent of the vote, the two top finishers will face off in a second round, perhaps as soon as next month.

In the last election, Abdullah dropped out after weeks of political crisis instead of competing in a runoff against Karzai, saying that the process was too corrupted to be fair. If fraud becomes a theme this time, one key question is whether the candidates will urge their followers into the streets to contest the result.

Voter turnout declined in the last election as the insurgency gained strength. In 2009, after more than 1 million fraudulent votes were thrown out, election observers calculated that, out of more than 15 million registered, about 4.5 million people had voted — about half the turnout in 2004. The Independent Election Commission estimated Saturday evening that about 7 million people voted this time.

Several polling stations reported that they ran out of ballots because so many voters turned up. At the Wazir Akbar Khan mosque in Kabul, not far from the U.S. Embassy, the site shut down once its 1,800 ballots had been used. Mohammad Wazir, the head of the polling site, said that under new rules instituted this year to prevent fraud, sites were not allowed to borrow ballots from nearby locations if they ran out.

In Washington, President Obama congratulated Afghans on their participation in what he called “historic elections.” The vote, he said, represents “another important milestone in Afghans taking full responsibility for their country as the United States and our partners draw down our forces.”

Throughout the day, reports of violence came in from the provinces. Interior Minister Omar Daudzai said Saturday afternoon that there had been 140 attacks across the country in the previous 24 hours and that nine police officers, seven soldiers and 89 insurgents had been killed. A Taliban spokesman said the movement’s fighters had launched 246 attacks, most of them targeting polling sites, but that number was not confirmed. In Konar province, 16 people, half of them Afghan security personnel, were wounded in fighting or explosions, officials said. And in Logar province, four voters were reported to have been wounded in an explosion.

The violence prevented nearly 1,000 polling stations — or about one in six nationwide — from opening, officials said.

There were also attempts at cheating. The Interior Ministry said that at least 14 people, including six government officials, had been arrested for attempted fraud. A woman and three men in Khost province were also arrested after being accused of trying to cast 1,067 votes for their preferred candidate.

Earlier Saturday at a command center in Wardak province, a Taliban stronghold, Afghan police officers and soldiers updated a map to keep track of a slew of insurgent activities. There had been no deadly attacks, making the day a relative success in terms of security, but the mood was still tense. Across the province, 120 polling centers were open, all of them with some level of protection from the army and police. The voter turnout was disappointing at many centers, but the Afghan military exulted in having done its job.

“We are pleased with our efforts,” said Col. Sami Badakshani, the executive officer of the Afghan army brigade responsible for security in the province.

U.S. military officials were instructed to remain invisible Saturday — far from the polls and from combat operations — to ensure that the election appeared “Afghan-owned.”

“There’s really not much we can do,” said Capt. Luke Beazley, the operations officer in the U.S. Army unit advising Wardak’s combat brigade.

Early on election morning, Rahmatullah, a bodyguard for Kabul’s mayor, received a call from his brother-in-law in the north-central province of Sar-e Pol. “He said, ‘We have been threatened by the Taliban not to go out and vote.’ I said, ‘Don’t worry about the Taliban, just go vote,’ ” Rahmatullah said after he voted in Kabul. “We are here to decide about the future of Afghanistan.”

Sieff reported from Wardak province. Sayed Salahuddin in Kabul contributed to this report.