Opponents of the far-right president-elect fear he will now plunge Brazil back into authoritarianism.
Far-right former army captain Jair Bolsonaro won Brazil's presidential election Sunday, according to official results that gave him 55.7 per cent of the vote with more than 88 per cent of the ballots counted.
His victory over leftist candidate Fernando Haddad marks a lunge to the right for Latin America's largest country, after a divisive campaign marked by widespread outrage at the political class - but also fears over Bolsonaro's denigrating remarks about women, gays and blacks.
Bolsonaro had an eight- to 10-point lead going in, according to two final opinion polls released on Saturday, which gave him about 55 percent of the vote.
Haddad, a former mayor of Sao Paulo, took 44.3 per cent of the vote, according to the results released by the Supreme Electoral Tribunal.
The runner-up has vowed to 'defend freedoms' of president-elect's opponents.
And while Haddad had made up ground - he trailed by as much as 18 points two weeks ago - he always needed a huge surge to defeat the far-right former army officer.
"This thing is going to turn around," Haddad, 55, buoyantly told thousands of supporters at his final campaign rally on Saturday.
Bolsonaro, 63, made his own final pitch on social media, the only place he has campaigned since an attacker stabbed him in the stomach at a rally last month, sending him to the hospital for three weeks.
"God willing, (it) will be our new independence day," he tweeted.
Bolsonaro supporters flooded the streets in front of his home in the neighborhood of Barra da Tijuca in Rio de Janeiro, waving Brazilian flags and lighting up the sky with fireworks.
"All these people here are outraged, upset about corruption and crime, and we are with Bolsonaro. The people have spoken. For the first time I feel represented," Andre Luiz Lobo, 38, a businessman who - not incidentally, given accusations of racism against his candidate - is black, said.
Bolsonaro, 63, a long-time congressman, will take office on January 1.
In his victory speech, broadcast via Facebook, he vowed to to "change Brazil's destiny together".
The speech was also marked by more divisive moments: he pledged to govern "following the Bible and the constitution," and said "we cannot continue flirting with socialism, with communism, populism and the extremism of the left."
One election, two Brazils
Coming on the heels of a punishing recession and staggering corruption scandal, the Latin American giant's elections have thrown up a spectacular cast of characters, even by the standards of these divisive, anti-establishment times.
Bolsonaro outrages a large part of the electorate - and many outside the country - with his overtly misogynistic, homophobic and racist rhetoric.
He once told a lawmaker he opposed that she "wasn't worth raping;" he has said he would rather see his sons die than come out as gay; and he commented after visiting one black community that they "do nothing - they're so useless I doubt they can procreate."
But an even larger portion of voters reject Haddad and the tarnished legacy of his Workers' Party.
Haddad is standing as a surrogate for jailed ex-president Luiz Inacio Lula da Silva, who led Brazil through the boom years of 2003 to 2010.
Lula remains the country's most popular politician, despite being accused of masterminding the massive pilfering of state oil company Petrobras. But the hugely divisive Workers' Party founder was barred from running because he is serving a 12-year prison sentence.
Haddad, who lacks Lula's natural charisma, has struggled to unite opposition to Bolsonaro, despite mounting fears over what the former army officer's presidency would look like.
Bolsonaro is unabashedly nostalgic for Brazil's brutal military dictatorship (1964-1985), and has been accused of authoritarian tendencies.
He once said the dictatorship's "mistake" was that it tortured, instead of killing, leftist dissidents and suspected sympathizers.
But in an anti-establishment climate, his law-and-order message has resonated.
The election looks set to be decided as much by Brazilians voting against something as for it.
"I'm not very enthusiastic, because I don't really like either candidate," Elias Chaim, 23, an engineering student and music producer, told AFP at a polling station facing the legendary beach of Copacabana in Rio de Janeiro.
"But I want to vote Haddad, because Bolsonaro's discourse of hate and intolerance is a risk for our country."
In Sao Paulo, the economic capital, Marcos Kotait, 40, a publicist, said he had "never seen such a polarized election."
"It used to be people would actually vote for what they wanted, and not just against something," he said.
Country in crisis
Running for the formerly minor Social Liberal Party, Bolsonaro is, according to many political analysts, a symptom of the crises ailing Brazil since the Workers' Party's 13 years in power came crashing to an end with the impeachment of Dilma Rousseff in 2016.
Among those crises: Brazil's economy shrank nearly seven percent during its worst-ever recession, from 2015 to 2016; the multi-billion-dollar Petrobras scandal has left voters disgusted with the seemingly bottomless corruption of politicians and business executives; and there is widespread outrage over violent crime, in a country that registered a record 63,880 murders last year.
Outgoing President Michel Temer, himself implicated in corruption, is set to leave office on January 1 as the most unpopular president in Brazil's modern democracy.
Brazil's 147 million voters can cast their until 2200 GMT.
The results are expected around 2300 GMT.