Jair Bolsonaro, a brash far-right congressman who has waxed nostalgic for Brazil's old military dictatorship, won the presidency of Latin America's largest nation Sunday as voters looked past warnings that he would erode democracy and embraced a chance for radical change after years of turmoil.
The former army captain, who cast himself as a political outsider despite a 27-year career in Congress, became the latest world leader to rise to power by mixing tough, often violent talk with hard-right positions. His victory reflected widespread anger at the political class after years of corruption, an economy that has struggled to recover after a punishing recession and a surge in violence.
"I feel in my heart that things will change," Sandra Coccato, a 68-year-old small business owner, said after she voted for Bolsonaro in Sao Paulo. "Lots of bad people are leaving, and lots of new, good people are entering. There's a light at the end of the tunnel."
In Rio de Janeiro, thousands of Bolsonaro supporters gathered on iconic Copacabana Beach, where fireworks went off. In Sao Paulo, Brazil's largest city, car horns could be heard honking and crowds celebrated as the results came in. There were also reports of clashes between his backers and opponents in Sao Paulo.
Speaking to supporters from his home in Rio, Bolsonaro recounted how he was stabbed while campaigning last month and almost died.
"I was never alone. I always felt the presence of God and the force of the Brazilian people," he said.
Bolsonaro, who ran on promises to clean up Brazil and bring back "traditional values," said he would respect the constitution and personal liberty.
"That is a promise, not of a party, not the vain word of a man. It's a promise to God," he said, standing next to his wife and many cheering supporters.
Later, he said in a Facebook Live transmission that he had received a call from some world leaders, including U.S. President Donald Trump who wished him good luck.
Addressing supporters in Sao Paulo, his rival, Fernando Haddad of the Workers' Party, did not concede or even mention Bolsonaro by name. Instead, his speech was a promise to resist.
"We have the responsibility to mount an opposition, putting national interests, the interests of the entire Brazilian people, above everything," Haddad said. "Brazil has never needed the exercise of citizenship more than right now."
He later added: "Don't be afraid. We are here. We are together!"
Brazil's top electoral court said Bolsonaro won with just over 55 percent of the vote, compared with just under 45 percent for Haddad.
Bolsonaro went into Sunday the clear front-runner after getting 46 percent of the vote to Haddad's 29 percent in the first round of voting on Oct. 7, when 13 contenders were on the ballot. Opinion polls in recent weeks had him leading by as much as 18 percentage points, but the race tightened in the last few days. Several Brazilian heavyweights came out against him, arguing that he was a direct risk to the world's fourth-largest democracy.
His rise was powered by disgust with the political system. In particular, many Brazilians were furious with the Workers' Party for its role in the mammoth graft scheme uncovered by the "Operation Car Wash" investigation. Haddad struggled to build momentum with his promises of a return to the boom times by investing in health and education and reducing poverty.
Along the way, Bolsonaro's candidacy also raised serious concerns that he would roll back civil rights and weaken institutions in what remains a young democracy. He frequently disparaged women, gays and blacks, and said he would name military men to his Cabinet.
Minutes after he was elected, several international human rights groups put out statements demanding that Bolsonaro respect Brazil's democracy.
In a highly unusual moment earlier Sunday, the chief justice of the Supreme Court, Jose Dias Toffoli, read out part of the Constitution to reporters after he voted.
"The future president must respect institutions, must respect democracy, the rule of law, the judiciary branch, the national Congress and the legislative branch," Toffoli said in remarks many took to be a rebuke of Bolsonaro and his more extreme positions.
As late as Sunday morning, Haddad was still holding out hope that he could win after receiving several key endorsements late Saturday.
Among them was a popular former Supreme Court justice, Joaquim Barbosa, who tweeted support for Haddad, saying Bolsonaro's candidacy scared him. Likewise, former Attorney General Rodrigo Janot, one of the biggest crusaders against corruption in the Workers' Party in recent years, also endorsed Haddad.
One of the most important endorsements, particularly for young people, came from YouTube personality Felipe Neto, whose channel has nearly 27 million followers.
Neto said he was troubled by Bolsonaro's comments a week ago that "red" leftists would be run out of Brazil.
"In 16 years of the (Workers' Party), I have been robbed, but never threatened," Neto said on Twitter.
The past few years in Brazil have been exceptionally turbulent. In 2016, then-President Dilma Rousseff of the Workers' Party was impeached and removed from office on charges that many on the left felt were politically motivated. The economy suffered a two-year recession and is only beginning to emerge, with growth stagnant and unemployment high.
Scores of politicians and executives have been jailed in the Car Wash corruption investigation, which uncovered a multibillion-dollar scheme to trade public contracts and official favors for bribes and kickbacks.
That instability unleashed sharp anger against the political class but also revealed deep divisions in Brazilian society, and the campaign was the most polarized in decades. There were numerous reports of politically motivated violence, especially directed at gay people.
Many observers predicted that a newcomer would emerge to harness the anti-establishment anger. Instead, support coalesced around Bolsonaro, who at the margins in Congress painted himself as just the strong man Brazil needed to dismantle a failing system.
Bolsonaro's campaign first gained traction with his promises to go after violent crime in a country that leads the world in homicides and where many Brazilians live in daily fear of muggings or burglaries. But his vows to loosen gun laws and give police a freer hand to use force have also raised concerns that his presidency could lead to a bloody crackdown and an erosion of civil rights.
The campaign gained momentum by winning over much of the business community with promises of enacting market-friendly reforms that would reduce the size of the Brazilian state, including cutting ministries and privatizing state companies.
"I hope that with these elections we're not signing a blank check again, and that we don't close our eyes to everything that has happened," said Jose Nobrega, a 53-year-old waiter in Mare, one of Rio's most violent neighborhoods.
AP writers Stan Lehman, Marcelo Silva de Sousa and Beatrice Christofaro contributed to this report.