With combat forces from the U.S.-led coalition winding down a 13-year presence and the mercurial Hamid Karzai stepping aside, the country's new leader will find an altered landscape as he replaces the only president Afghans have known since the Taliban were ousted in the wake of the Sept. 11 attacks.
But for some progress, particularly with women's rights, the country's situation is inauspicious, especially with its poor security and battered economy. Yet despite spiraling carnage and grave disappointments, Afghans by the millions crowded mosque courtyards and lined up at schools to vote, telling a war-weary world they want their voices heard.
Nazia Azizi, a 40-year-old housewife, was first in line at a school in eastern Kabul. "I have suffered so much from the fighting and I want prosperity and security in Afghanistan. That is why I have come here to cast my vote," she said. "I hope that the votes that we are casting will be counted and that there will be no fraud in this election."
Partial results could come as early as Sunday, but final results were not expected for a week or more.
International combat troops are supposed to depart by the end of the year, leaving Afghan security forces - not completely battle-tested and plagued with insurgents even among their ranks - to fight alone against what is likely to be an intensified campaign by the Taliban to regain power.
A security agreement with the United States would allow thousands of foreign troops to remain in the country to continue training security forces after 2014. Karzai - perhaps trying to shake off his image as a creation of the Americans - has refused to sign it, but all eight presidential candidates say they will.
In congratulating Afghanistan on the election, U.S. President Barack Obama said it represented "another important milestone in Afghans taking full responsibility for their country as the United States and our partners draw down our forces."
"These elections are critical to securing Afghanistan's democratic future, as well as continued international support, and we look to the Afghan electoral bodies to carry out their duties in the coming weeks," Obama said in a statement.
Secretary of State John Kerry said the "vote demonstrates how committed the Afghan people are to protecting and advancing their democracy." He added that the United States "remains ready to work with the next president of Afghanistan."
The U.N. Security Council issued a press statement commending "the courage of the Afghan people to cast their ballot despite the threat and intimidation by the Taliban and other extremist and terrorist groups."
In general, there do not appear to be major policy differences toward the West among the front-runners: Abdullah Abdullah, Karzai's top rival in the last election; Ashraf Ghani Ahmadzai, an academic and former World Bank official; and Zalmai Rassoul, a former foreign minister. A runoff is widely expected since none is likely to get the majority needed for an outright victory.
All eight also preach against fraud and corruption and vow to improve security, while they do differ on other issues such as the country's border dispute with Pakistan.
The runup to the election was troubling: the Islamic radicals of the Taliban, reviled by many but still popular in some areas, view the entire enterprise as the work of outsiders and infidels, and they vowed to disrupt it by targeting polling centers and election workers.
To drive home the threat, insurgents in recent weeks stepped up shootings and bombings in the heart of Kabul to show they are capable of striking even in highly secured areas. A restaurant popular with foreigners and one of the capital's main hotels were hit, killing many. Suicide bombers struck relentlessly.
On Friday, veteran Associated Press photographer Anja Niedringhaus was killed and AP reporter Kathy Gannon was wounded when a local policeman opened fire as they sat in their car on the outskirts of Khost, in eastern Afghanistan. The two were at a security forces base, waiting to move in a convoy of election workers delivering ballots - apparent victims of an "insider attack" in which the very people tasked with protection turn out to be insurgents.
On Saturday, the excitement over choosing a new leader appeared to overwhelm the fear of bloodshed in many areas.
Karzai cast his ballot at a high school near the presidential palace.
"Today for us, the people of Afghanistan, is a very vital day that will determine our national future," he said, his finger stained with the indelible ink being used to prevent people from voting twice.
Karzai has been heavily criticized for failing to end the endemic poverty or clean up the government in a country that Transparency International last year ranked among the three most corrupt in the world, alongside Somalia and North Korea.
And the country is so unstable that the very fact that elections are being held is touted as a success. The Taliban retain significant support, particularly among ethnic Pashtuns and Afghans in the southern provinces where the movement originated. The Asia Foundation, a nonprofit international development organization, found last year that a third of Afghans, mostly Pashtuns and people living in rural areas, had sympathy for the Taliban and other armed opposition groups - despite U.N. findings that Taliban attacks are responsible for the most civilian casualties.
On Saturday, dozens of planned polling centers did not open because of rocket and gunfire attacks. A bomb exploded in a school packed with voters in the Mohammad Agha district of Logar province, wounding two men, one seriously, said local government spokesman Din Mohammad Darwesh.
Afghan Interior Minister Mohammad Umar Daudzai said 20 people - 16 Afghan security forces and four civilians - were killed in 140 attacks or attempted attacks over 24 hours. But the feared a wide-scale disruption did not materialize.
The turnout was so high that some polling centers ran out of ballots, one of the main points of criticism to emerge from an otherwise relatively smooth process. They also extended voting by an hour, to 5 p.m. local time (1230 GMT) to accommodate those still in line.
Independent Election Commission chairman Ahmad Yousuf Nouristani said estimates showed more than 7 million ballots were cast, although he cautioned that was based on preliminary information. He said that in all, 6,218 polling centers opened.
It was a stark difference from the last presidential elections in 2009. Widespread allegations of fraud marred the vote and led to a third of the ballots for Karzai being disqualified, depriving him of the majority needed to avoid a runoff. His nearest rival, Abdullah Abdullah, quit before a second round could be held, saying he did not believe it would be fair either.
"We slapped the face of Afghanistan's enemy, which claims Afghanistan is not ready for democracy. We proved that we are accepting democracy as a process," said Shukria Barekzai, one of nearly 70 female lawmakers in the 249-seat parliament. "Today were the real elections, because nobody knows who will be the next president."
Karzai, the only president the country has known since the Islamic movement was ousted, is constitutionally barred from a third term.
Martine van Bijlert, co-director of an independent research group called Afghanistan Analysts Network, noted the elections come as the country braces for the withdrawal of international combat troops.
"They come at a time when Afghanistan is in a transition," she said. "There is this sense of uncertainty what is the future going to bring."
In addition to the presidential ballot, voters selected provincial council members.
Men in traditional tunics and loose trousers and women clad in all-encompassing burqas waited in segregated lines at polls under tight security. At a Kandahar hospital-turned-polling station, the men's line stretched from the building, through the courtyard and out into the street. In Helmand province, women pushed, shoved and argued as they pressed forward in a long line.
"I went to sleep with my mind made up to wake up early and to have my say in the matter of deciding who should be next one to govern my nation," said Saeed Mohammad, a 29-year-old mechanic in the southern city of Kandahar. "I want to be a part of this revolution and I want to fulfill my duty by casting my vote so that we can bring change and show the world that we love democracy."
Women also turned out in heavy numbers.
Hundreds of thousands of Afghan police and soldiers fanned out across the country, searching cars at checkpoints and blocking vehicles from getting close to polling stations. All voters were searched before being allowed to enter the polling stations. Once in, they showed their ID cards, dipped a finger in indelible ink, then went behind a makeshift cardboard booth and made their choices for who should lead the country into an uncertain future.