As counting neared completion in Quito and around the country, leftist candidate Lenin Moreno of the ruling Alianza PAIS (Country Alliance) party held a narrow lead over conservative opponent Guillermo Lasso.
Preliminary figures released by the country's National Electoral Council (CNE) had Moreno with 51.1% for the votes cast, and Lasso at 48.9%, with 96.22% of the votes counted.
Around 8.30 p.m. local time (7.30 p.m. ET) Moreno declared himself the winner, but shortly that after a nongovernmental organization that had been monitoring the result said that it was a virtual tie.
Ecuadorean state media
declared Moreno -- outgoing President Rafael Correa's chosen successor -- the victor.
While no official announcement has yet been made by the CNE, the body said that Moreno was ahead by 2 percentage points and the trend was irreversible.
Hundreds of demonstrators gathered outside the National Election Council offices in Quito and Guayaquil to protest the election outcome, pictures from the scenes showed.
Lasso, a former banker, said that he was requesting a recount. "Delegates from our political alliance will challenge the results," Lasso said. "We will not allow a distortion of the popular will."
A recount could take weeks to implement.
Moreno, who is confined to a wheelchair, challenged the allegation that there was fraud. "We have completely accurate data," he said. "We have won the elections."
Moreno, who is universally referred to by his first name, Lenin, by supporters, tweeted a photo of his victory speech with the message: "Long live Ecuador! Welcome fighters of peace and of life."
"Official results from the National Electoral Council, a difference of more than two percentage points. Lenin is our president," President Correa said. "The moral fraud committed by the right will not go unpunished."
Moreno, himself a former vice president, told supporters that he will work "for those who voted for me and for those who did not," according to the government-run El Telegrafo newspaper.
His opponent called on supporters to take to the streets to peacefully protest the result.
"Let's act in a peaceful but firm manner," Lasso's tweet read. "We must go to the streets and say 'don't steal my vote' because we want a change in Ecuador."
Voters in Latin America have been swinging rightwards, with recent wins in Brazil and Argentina for conservative candidates challenging leftist governments in the region. Given Ecuador's potential recount, it is too early to tell whether Moreno's apparent win will buck this trend.
Relief for Assange?
The apparent result will come as a relief for Wikileaks founder Julian Assange, who has been holed up in the Ecuadorean embassy in London for almost five years to avoid facing sexual assault charges in Sweden.
As a campaign promise, Lasso had vowed to have Assange removed from his quarters in London within 30 days of taking office. Moreno had indicated that his government would continue to shelter Assange from prosecution.
If apprehended by the Swedes, Assange has said he could eventually end up in the United States
, where he could be charged and tried over the leak of confidential US documents to the public via WikiLeaks.
Assange struck back at Lasso's pledge to remove him with a tongue-in-cheek tweet, "cordially inviting" Lasso to leave Ecuador.
"I cordially invite Lasso to leave Ecuador within 30 days (with or without his tax haven millions)," the tweet read, echoing Lasso's language in his pledge to remove Assange from the London embassy.