(Adds U.S. reaction paragraphs 11-13, 17-19)
By Mirwais Harooni and Jessica Donati
KABUL/KANDAHAR, Afghanistan, April 5 (Reuters) - A fghanistan's presidential election closed on Saturday amid relief that attacks by Taliban fighters were fewer than feared for a vote that will bring the first-ever democratic transfer of power in a country plagued by conflict for decades.
It will take six weeks for results to come in from across Afghanistan's rugged terrain and a final result to be declared in the race to succeed President Hamid Karzai.
This could be the beginning of a potentially dangerous period for Afghanistan at a time when the war-ravaged country desperately needs a leader to stem rising violence as foreign troops prepare to leave.
"Today we proved to the world that this is a people driven country," Karzai, wearing his trademark green robe and a lambskin hat, told his nation in televised remarks.
"On behalf of the people, I thank the security forces, election commission and people who exercised democracy and ... turned another page in the glorious history of Afghanistan."
One of the eight candidates will have to score over 50 percent of the vote to avoid a run-off with his nearest rival.
The Taliban threat to wreck the vote through bombings and assassination failed to materialise, and violent incidents were on a far smaller scale than feared.
Turnout was seven million out of 12 million eligible voters, or about 58 percent, according to preliminary estimates, election commission chief Ahmad Yousuf Nuristani told reporters.
That was well above the 4.5 million who voted at the last election in 2009 which was marred by widespread fraud.
"I am here to vote and I am not afraid of any attacks," said Haji Ramazan as he stood in line at a polling station in rain-drenched Kabul. "This is my right, and no one can stop me."
In Washington, President Barack Obama congratulated the Afghan people on the elections.
"We commend the Afghan people, security forces, and elections officials on the turnout for today's vote - which is in keeping with the spirited and positive debate among candidates and their supporters in the run-up to the election," Obama said in a statement.
"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 to adjudicate the results - knowing that the most critical voices on the outcome are those of Afghans themselves," Obama said.
The United States could point to the advance of democracy in one of the world's most violent countries as a success as it prepares to withdraw the bulk of its troops this year.
It has spent $90 billion on aid and security training since helping Afghan forces to topple a strict Islamist Taliban regime in 2001, but U.S. support for Afghanistan's fight against the Taliban has faded.
As U.S. troops get ready to go home, the Taliban threat and uncertainty over neighbour Pakistan's intentions leave the worry that Afghanistan could enter a fresh cycle of violence, and once again become a haven for groups like al Qaeda.
The United States has been at odds with Karzai who has refused U.S. entreaties to sign a bilateral security agreement that would permit about 8,000 U.S. troops to remain in the country after the formal U.S. withdrawal at the end of the year.
U.S. officials are keeping open the option of leaving behind a troop contingent for training Afghan forces and for a counter-terrorism mission if an agreement can be signed later this year by Karzai's successor.
"The United States remains ready to work with the next president of Afghanistan. We will continue to stand with the people of Afghanistan as they work to build a democratic future," U.S. Secretary of State John Kerry said in a statement.
During Saturday's election, there were dozens of reports of minor roadside bombs, attacks on polling stations, police and voters. In the eastern province of Kunar alone, two voters died and 14 were wounded, while 14 Taliban militants were killed.
Interior Minister Umer Daudzai said nine policemen, seven soldiers, 89 Taliban fighters were killed in the past 24 hours across the country, adding that four civilians were also killed.
Dozens died in a spate of attacks in the preceding weeks. A veteran Associated Press photographer was killed and a senior correspondent of the same news agency was wounded on Friday when a policeman opened fire on the two women in the east as they reported on preparations for the poll.
KABUL SEALED OFF
Most people had expected the election to be better run than the chaotic 2009 vote that handed Karzai a second term.
The constitution barred Karzai from seeking another term. But, after 12 years in power, he is widely expected to retain influence through politicians loyal to him.
Former foreign ministers Abdullah Abdullah and Zalmay Rassoul, and former finance minister Ashraf Ghani were regarded as the favourites to succeed Karzai.
More than 350,000 Afghan troops were deployed, guarding against attacks on polling stations and voters. The capital, Kabul, was sealed off by rings of roadblocks and checkpoints.
In the city of Kandahar, cradle of the Taliban insurgency, the mood was tense. Vehicles were not allowed to move on the roads and checkpoints were set up at every intersection.
Hamida, a 20-year-old teacher working at a Kandahar polling station, said more than a dozen women turned up in the first two hours of voting and added that she expected more to come despite the threat of an attack by the Taliban.
"We are trying not to think about it," she said, only her honey-brown eyes visible through her black niqab.
Raising questions about the legitimacy of the vote even before it began, the election commission announced that at least 10 percent of polling stations were expected to be shut due to security threats, and most foreign observers left Afghanistan in the wake of a deadly attack on a hotel in Kabul last month.
In some areas of the country voters complained that polling stations had run out of ballot papers. The interior ministry said six officials - including an intelligence agent - were detained for trying to rig the vote, and elsewhere several people were arrested for trying to use fake voter cards.
RISK OF DELAY
If there is no outright winner, the two frontrunners would go into a run-off on May 28, spinning out the process into the holy month of Ramadan when life slows to a crawl.
A long delay would leave little time to complete a pact between Kabul and Washington to keep up to 10,000 U.S. troops in the country beyond 2014.
Karzai has rejected the pact, but the three frontrunners have pledged to sign it. Without the pact, far weaker Afghan forces would be left on their own to fight the Taliban.
The election is a landmark after 13 years of struggle that has killed at least 16,000 Afghan civilians and thousands more soldiers. Nearly 3,500 members of the U.S.-led coalition force have died since deployment in the country over a decade ago.
Karzai's relations with the United States became increasingly strained as Afghan casualties mounted. He also voiced frustration with Washington over a lack of pressure on Pakistan to do more to stop the Taliban based in the borderlands.
Although his departure marks a turning point, none of his would-be successors would bring radical change, diplomats say.
"Whether the election will be the great transformative event that everybody expects is, I think, delusional." Sarah Chayes, a South Asia expert at the Carnegie Endowment for International Peace told a media briefing on the eve of the vote. (Additional reporting by Hamid Shalizi in KABUL; Sarwar Amani in KANDAHAR, Steve Holland and Arshad Mohammed in WASHINGTON; Writing by John Chalmers and Maria Golovnina; Editing by Simon Cameron-Moore and Gunna Dickson)
Our Standards: The Thomson Reuters Trust Principles.