Holding a nationwide election in a vast, impoverished and insurgency-ridden country was the easy part.
Now comes the difficult task of determining whether Afghanistan's watershed presidential vote Thursday was free and fair, or enough so that the result, when it emerges, will be credible. A definitive count will take weeks, and the contest may have to be settled with a runoff.
The vote, which pitted incumbent President Hamid Karzai against a trio of major rivals and more than two dozen lesser contenders, is viewed by the West as a test for the legitimacy of Afghanistan's central government. That's a matter of growing urgency in a nation burdened by warfare, pervasive corruption, a booming drug trade and seemingly intractable poverty.
The end of 10 hours of balloting, extended by an hour in a bid to boost turnout, brought a collective sigh of relief from electoral officials. Despite scattered violence that killed 26 people in various parts of the country, anticipated large-scale attacks on voters, election workers and polling places did not materialize.
Although Taliban intimidation appeared to have kept some voters home, officials were already saying that turnout, though not as high as hoped, probably had been sufficient to reflect national sentiment.
And though many allegations of election irregularities surfaced -- such as reports of ballot box stuffing and of indelible ink that wasn't -- there was little immediate evidence of widespread, systematic fraud, election observers said.
"All things considered, we're cautiously optimistic that it was a good day for the country," said Aleem Siddique, a spokesman for the United Nations mission in Afghanistan.
In Washington, White House Press Secretary Robert Gibbs said President Obama was "enormously proud of the millions of Afghanis that ignored the threats of harm and violence to exercise their right to choose their president and provincial council leaders."
Most of those killed in election day attacks were members of security forces, according to official reports. Eight Afghan soldiers, nine police officers and nine civilians died, the ministries of defense and interior said after the voting ended. In addition, the U.S. military reported the death of an American soldier in eastern Afghanistan.
The 43 U.S. military deaths in July were the highest monthly tally since the war began in 2001, and the August toll is on track to be even higher.
Obama has called the fighting in Afghanistan a "war of necessity," declaring this week that "if left unchecked, the Taliban insurgency will mean an even larger safe haven from which Al Qaeda would plot to kill more Americans."
Early turnout estimates were below 50%, considerably lower than in 2004, when the first direct presidential election was held.
Turnout appeared lowest in the south, where fighting this summer has been intense. Thousands of American troops are deployed in Kandahar and Helmand provinces, where the insurgency has its deepest roots.
Suspected Taliban militants lobbed rockets at polling places in both provinces, frightening away many voters who had already been subject to weeks of intimidation.
"There were 'night letters' posted by my mosque, and it scared me," said Najibullah Pushtoon, a 35-year-old teacher in the city of Kandahar, referring to threats from the Taliban.
The low southern turnout could spell trouble for Karzai, who was already seen as facing an uphill battle to muster the majority of the vote needed to win a first-round victory. The south is dominated by the Pashtun ethnic group, to which the president belongs.
Turnout was considerably higher in the relatively peaceful north, where ethnic Tajiks hold sway. That bodes well for Karzai's chief rival, former Foreign Minister Abdullah Abdullah, who is part Tajik.
In Kabul, the capital, voting got off to a sluggish start but picked up in the late afternoon. Still, it appeared that fewer people had voted than in the last presidential election.
Those who did come to the polls displayed an unmistakable pride.
"It's for me, and it's for my country," said a baby-faced 18-year-old named Nasir, who was voting for the first time. "If it's dangerous, I don't care. I'm happy."
At a polling place in a girls high school in Kabul, election worker Murza Mohammed Ahmadi made a ritual of the vote's opening. He turned a large Tupperware-type container upside down, shook it to show that it was empty, then fastened it shut with plastic ties.
"And now we vote," he said with satisfaction.
Officials had originally said a preliminary tally would be released Saturday, but those first results are now expected early next week.
In the capital, security was among the tightest ever seen in the city. Police were stationed on nearly every corner; streets where polling places were located were blocked off with barricades or red-and-white police tape. Voters had to submit to thorough searches; police popped open car trunks and turned people's cellphones off and on.
But even stringent precautions did not stave off attacks. At least five explosions, one of them at a polling station, were reported in Kabul, and for the second day in a row, police and suspected insurgents exchanged gunfire in the city center. The clash left at least two militants dead.
Karzai came out early to vote, posing for the cameras with his ink-stained index finger raised, proof that he had cast his ballot. "Come out and vote," he urged his compatriots.
The vote was a sharp reminder of the Afghan leader's falling-out with the West. Five years ago, he was the darling of the Bush administration, but those ties steadily frayed. During this campaign, the international community was dismayed by his deal-making with some notorious former warlords, one of whom is his running mate and another of whom was allowed back into the country just days before the vote in exchange for his backing.
Though many voters have found the recent years disillusioning, the day offered a strong display of faith in the democratic process.
Mohammed Akbar, disabled since childhood, made his way into a Kabul polling station by propelling himself on his callused hands. When he reached the registry, he paused to straighten his turban and take a deep breath.
"Of course I am here," he said. "It's my right."