Tunisia's incumbent President Moncef Marzouki on Monday appeared set for a runoff vote against an anti-Islamist party ex-premier after the first free leadership vote since the 2011 revolution that sparked the Arab Spring.
The election is a milestone in the North African country where a popular uprising set off a chain of revolts that saw several Arab dictators toppled by citizens demanding democratic reform.
The campaign manager for Marzouki said he is neck and neck with former premier Beji Caid Essebsi, the pre-polling favourite among 27 candidates vying for the top job.
"At the worst we are even but at best we're between two and four percent ahead," Adnene Mancer told reporters after polling closed.
"Our chances are good as we go into a runoff" next month, he said.
But the camp of Essebsi, the 87-year-old political veteran whose anti-Islamist Nidaa Tounes party won October's parliamentary polls, said he had come out ahead in Sunday's vote.
Essebsi, "according to preliminary estimates, is ahead and has a large lead", his campaign manager Mohsen Marzouk told journalists.
But with Essebsi "not far short" of the absolute majority needed to win outright, a second round was likely, Marzouk added.
Marzouki's campaign manager said he was concerned that "fraud" had been committed by the Essebsi camp, and urged election monitors to stay vigilant.
Exit polls conducted by a private organisation gave Essebsi between 42.7 percent and 47.8 percent of the vote with Marzouki trailing at between 26.9 percent and 32.6 percent, a state television report said.
Official results from what Prime Minister Mehdi Jomaa called a "historic day" will be known by Wednesday and a runoff second round vote will be held in late December if there is no outright winner.
Marzouki called on "all democratic forces" to back him in a second round against his rival.
Another presidential hopeful, Hamma Hammami, who according to exit polls came in third, told the media that his political group will meet "as soon as possible" to examine how they should vote in case of a runoff.
Though Tunisia's march towards democracy has been fraught by crisis, it has won international plaudits for not slipping into the post-revolution chaos seen by other Arab Spring states, such as neighbour Libya.
EU foreign affairs chief Federica Mogherini called the election a further step in Tunisia's "democratic transition" and said it was up to the people to "complete the electoral process with transparency and respect".
Whatever the outcome, Tunisians hailed the election as a landmark which they hoped would lead to economic and political stability.
"This election is very important. It's the culmination of the revolution and something that we really should not pass up," said one observer who gave his name only as Moez.
Bechir Yahyaoui could hardly control his emotions as he voted in Tunis, saying that for once he was "voting for who I want, with no pressure, no bribes".
"Before (under Ben Ali) you had to go and vote, regardless of the outcome. This time the election is free and transparent," he said.
Turnout was around 64.6 percent, authorities said, with some 5.3 million people eligible to vote.
Tens of thousands of police and troops were deployed to guarantee security amid fears that Islamist militants might seek to disrupt the polling.
Other candidates included ministers who served under ousted dictator Zine El Abidine Ben Ali, leftwinger Hammami, business magnate Slim Riahi and a lone woman, magistrate Kalthoum Kannou.
Until the revolution, Tunisia knew only two presidents -- Habib Bourguiba, the "father of independence" from France in 1956, and Ben Ali, who deposed him in a 1987 coup.
To prevent another dictatorship, presidential powers have been restricted under a new constitution, with executive prerogatives transferred to a premier from parliament's top party.
Essebsi's campaign focused on "state prestige", with a wide appeal to Tunisians dissatisfied with Islamist rule in the post-revolution era.
But his critics have warned that Essebsi is out to restore the old regime, having served under both former presidents.
Marzouki argues that only he can preserve the gains of the uprising, while his critics say he hijacked the spirit of the revolution by allying himself with the moderate Islamist party Ennahda in 2011.
The rule of Ennahda, which came second in the October parliamentary election, was marred by a surge of radical Islamism and the assassination of two leftist politicians by jihadist suspects.
If Essebsi wins he will have to form a coalition government, even with Ennahda, because Nidaa Tounes fell short of securing an absolute majority in October.
Whoever wins, the economy will be a priority, with unemployment, a leading cause of the revolution, running at 15 percent.