Ecuador plunged into crisis Sunday night after a disputed presidential vote, with leftist candidate Lenín Moreno headed to a narrow victory and his conservative opponent denouncing the results as fraudulent. 

The race was a political barometer for the strength of long-dominant leftist parties in South America that have been in retreat after electoral losses. Ecuador’s results appeared to buck that trend. 

With more than 96 percent of the ballots counted, Moreno led 51 percent to 49 percent over right-wing challenger Guillermo Lasso, who insisted that he was the real winner. Clashes broke out in several cities, with voters screaming at one another in the streets and many fearing an escalating standoff.

Citing an exit poll by the respected Cedatos firm showing him winning by a comfortable margin, Lasso gave an emotional speech declaring victory as soon as voting closed. “Fight!” he told his supporters, well before the first official tallies were released. “We won’t let them cheat us!”

At a rally soon after, Moreno told his cheering supporters that he had won, and the whipsaw effect continued through the evening. “Onward to victory!” he shouted. “We’ll continue changing Ecuador for the better.”

Ecuadoran President Rafael Correa, center, greets supporters after casting his vote at a school in Quito during the presidential election. (Juan Ruiz/AFP via Getty Images)

On Twitter, President Rafael Correa said violence had broken out in Quito and several other cities. “What they can’t accomplish at the polls, they’re trying to achieve by force,” wrote Correa, who has been in power since 2007 and was ineligible to run again. 

Correa declared Moreno, his former vice president, the victor, even though election authorities have yet to do so. “The revolution has triumphed again in Ecuador,” he said, dancing and singing onstage with Moreno at an evening rally.

But the government’s opponents seemed in no mood to concede defeat, demanding a recount and vowing to challenge the results in court. “The government they are trying to install will be an illegitimate one,” Lasso told his angry supporters, warning Correa, “You’re playing with fire.”

The results were also a reprieve for Julian Assange, whose asylum protection at Ecuador’s embassy in London was on the line. Lasso said he would evict Assange within 30 days from the embassy, where the WikiLeaks founder took refuge in 2012. Moreno has said he will let Assange stay.

“I cordially invite Lasso to leave Ecuador within 30 days (with or without his tax haven millions),” Assange wrote in a Twitter post Sunday night. taunting Lasso with a reference to accusations the candidate has millions stashed in offshore accounts.

Lasso and his supporters began celebrating in the streets of the capital, waving flags and honking car horns wildly as soon as several exit polls showed him winning. Their euphoria switched to outrage when the official results showed Moreno leading. Lasso’s supporters gathered outside the headquarters of the country’s election authorities, then broke through police barricades and surged toward the building, with television cameras showing them facing off against riot police with shields.

Ecuador’s disputed outcome is one of several South American conflicts that have occurred in recent days, along with clashes in Venezuela and Paraguay. 

Election observers from the Organization of American States and other groups had yet to make statements about the integrity of the vote. A respected nongovernmental organization, Participación Ciudadana, said its exit poll results showed a tie between the two candidates.

Correa’s decade in power has left Ecuadorans sharply divided, and with his legacy on the line, his government threw its full weight behind Moreno, 64.

Lasso, 61, a former banker, offered Ecuadorans a message of change and bet that frustration about the country’s sagging economy and Correa’s heavy-handed style would lift him to an upset. 

“We need new ideas. Everything is stagnant here,” said Luzmila ­Muñoz, 47, a chemical engineer who voted for Lasso in a middle-class sector of Quito. “Ten years is enough,” she said, referring to Correa.

Right-wing candidates have won recent presidential contests in Argentina and Peru, after a long period when left-wing populists such as Correa seemed invincible, using a commodity boom to cut poverty and cultivate a broad base of support. 

But with prices for oil and other exports slumping, the region has shifted to the right, and many leftists   saw the mild-mannered Moreno as their best chance to break the trend. Moreno, who was shot during a 1998 carjacking, would be the first candidate who uses a wheelchair to win a presidential race in Latin America.

“He’ll fight for equality, because he knows what it’s like to be disadvantaged,” said Janet Bravo, 40, who cast her vote for Moreno in the hillside neighborhood of ­Comité del Pueblo. Bravo, who owns a small office supply shop, said she has been able to save money in recent years because the government provided her two young children with free health care.

Moreno’s campaign was counting on voters such as Bravo to be wary of what sort of change a Lasso win would bring to their lives.

“I’m afraid we’ll go back to the way things were before,” said Erick Lara, 22, an Afro-Ecuadoran who is studying to be a chef. He credited the Correa government for promoting racial equality and said his mother was able to buy a home because of a government loan. “We have more opportunities now,” he said.

Michael Shifter, president of ­Inter-American Dialogue, a Washington think tank, said Moreno’s apparent victory showed that left-wing governments in South America may be more resilient than many believe. 

“Although Ecuador’s economic situation has recently worsened and there are serious questions about government corruption, most voters recognized advances in education, health care and especially infrastructure,” he said. “Moreno promised to give a new push and build on these gains.”

But the disputed, narrow results suggested that Moreno would face immediate challenges in governing a badly divided country in a region that has turned increasingly volatile.