RIO DE JANEIRO — Brazil on Sunday became the latest country to drift toward the far right, electing a strident populist as president in the nation’s most radical political change since democracy was restored more than 30 years ago.
He won by tapping into a deep well of resentment at the status quo in Brazil — a country whiplashed by rising crime and two years of political and economic turmoil — and by presenting himself as the alternative.
“We have everything we need to become a great nation,” Mr. Bolsonaro said Sunday night shortly after the race was called in a video broadcast on his Facebook account. “Together we will change the destiny of Brazil.”
He appeared eager to dispel concerns that he would govern despotically, saying his government would be a “defender of the Constitution, democracy and liberty.”
Mr. Bolsonaro, who will take the helm of Latin America’s biggest nation, is further to the right than any president in the region, where voters have recently embraced more conservative leaders in Argentina, Chile, Peru, Paraguay and Colombia. He joins a number of far-right politicians who have risen to power around the world, including Italy’s deputy prime minister, Matteo Salvini, and Prime Minister Viktor Orban of Hungary.
“This is a really radical shift,” said Scott Mainwaring, a professor at Harvard University’s Kennedy School of Government who specializes in Brazil. “I can’t think of a more extremist leader in the history of democratic elections in Latin America who has been elected.”
With 98 percent of votes counted, Mr. Bolsonaro was ahead with 55 percent, guaranteeing him a win over Fernando Haddad of the leftist Workers’ Party, who had 45 percent.
Hundreds of supporters gathered outside Mr. Bolsonaro’s seaside home in Rio de Janeiro, jumping and hugging one another when the results were announced. As golden fireworks lit up the sky, they chanted “mito,” or legend, paying homage to their president-elect.
Reeling from the deepest recession in the country’s history, a corruption scandal that tarnished politicians across the ideological spectrum, and a record-high number of homicides last year, Brazilians picked a candidate who not only rejected the political establishment but at times also seemed to reject the most basic democratic tenets.
Mr. Bolsonaro’s victory caps a bitter contest that divided families, tore friendships apart and ignited concerns about the resilience of Brazil’s young democracy.
Many Brazilians see authoritarian tendencies in Mr. Bolsonaro, who plans to appoint military leaders to top posts and said he would not accept the result if he were to lose. He has threatened to stack the Supreme Court by increasing the number of judges to 21 from 11 and to deal with political foes by giving them the choice of extermination or exile.
Mr. Bolsonaro, 63, a former army captain who has been a member of Congress for nearly three decades, beat a crowded field of presidential contenders, several of whom entered the race with bigger war chests, less baggage and the backing of powerful political parties.
Mr. Bolsonaro said that President Trump called to congratulate him, calling it “obviously a very friendly contact.”
Part of the reason for Mr. Bolsonaro’s victory was the collapse of the left. Many cried foul after former President Luiz Inácio Lula da Silva, the longtime front-runner in the race, was ruled ineligible to run after he was imprisoned in April to start serving a 12-year sentence for corruption and money laundering.
His Workers’ Party had won the last four presidential elections, and Mr. da Silva, a former metalworker, retained a devoted following among poor and working-class Brazilians who felt represented by him personally and had benefited from his party’s social inclusion policies.
But many more Brazilians showed through their votes that they had had enough of the Workers’ Party, which steered the country from 2003 to 2016 through a boom-and-bust cycle that ended in an economic morass and the impeachment of his successor, President Dilma Rousseff.
Despite his influence, Mr. da Silva was not able to pull off the last-minute transfer of votes to the candidate chosen to replace him on the ballot, the bookish and urbane — but less charismatic — Mr. Haddad.
And for those Brazilians who saw the political establishment they inherited from the Workers’ Party as venal, Mr. Bolsonaro was an enthralling candidate.
He accomplished little in his long legislative career, but his roster of offensive remarks — he said that he’d rather his son die than be gay and that women don’t deserve the same pay as men — was interpreted by many as bracing honesty and evidence of his willingness to shatter the status quo.
“The way he’s run his campaign is very clever,” said Matias Spektor, a professor of international relations at Fundação Getulio Vargas University. “He has managed to align himself with the institutions that Brazilians still believe in: religion, family and armed forces.”
Mr. Bolsonaro, the patriarch of a family from Rio de Janeiro that includes three sons who are also lawmakers, ran an insurgent campaign that defied the political playbook that brought his predecessors to power.
A year ago, Mr. Bolsonaro’s bid was widely regarded by political veterans in Brasília as fanciful in a nation renowned for the cordiality and warmth of its people. Some of the candidate’s remarks were so offensive the country’s attorney general earlier this year charged him with inciting hatred toward black, gay and indigenous people. In a country where most of the population is not white, this alone might have seemed to disqualify him.
Yet, the vitriol and outrage Mr. Bolsonaro brought to the campaign trail as he traveled around the country largely mirrored Brazilians’ dystopian mood.
Nearly 13 million people are unemployed. The homicide rate is among the highest in the world — last year, 63,880 people were killed. And Mr. da Silva, the former president many had idolized, had left office with an approval rating of 87 percent only to become the most prominent scalp taken by a corruption scandal that has ensnared dozens of the country’s political and business leaders.
Part of Mr. Bolsonaro’s appeal lay in the extreme solutions he proposed to assuage the population’s anger and fear of violence.
He vowed to give the police forces in Brazil — some of the most lethal in the world — expanded authority to kill suspects, saying with trademark bluntness that a “good criminal is a dead criminal.” He also promised to lower the age of criminal responsibility, impose stiffer sentences for violent crimes and ease Brazil’s gun ownership restrictions so civilians could better protect themselves.
“Violence must be reduced because otherwise we are headed toward total chaos,” said Roberto Levi, 36, a police officer in Rio de Janeiro who voted for Mr. Bolsonaro.
Over the past two years, while many of Brazil’s traditional political parties and powerful kingmakers were busy defending themselves against corruption allegations stemming from the investigation known as Lava Jato, Mr. Bolsonaro flew around the country, drumming up support, particularly among young men, and in comparatively wealthier and whiter areas.
While rivals spent small fortunes on marketing firms, video editors and consultants, Mr. Bolsonaro relied primarily on Facebook, Twitter, YouTube and the instant messaging service WhatsApp to communicate with voters and expand his base.
Opponents enjoyed far more advertising time on television and radio — which is allotted by party size — and rolled out slickly edited campaign materials. But Mr. Bolsonaro’s campaign drowned them out with a bare-bones, scrappy communications strategy. He and his sons broadcast shaky, poorly lit videos on Facebook and Instagram in which Mr. Bolsonaro cracked jokes, took aim at adversaries and bemoaned the state of Brazil.
On WhatsApp, supporters created hundreds of groups to share memes, videos and messages that often contained falsehoods and misleading content that cast Mr. Bolsonaro in a positive light and disparaged his rivals.
One dominant message, spread widely via WhatsApp, asserted with no evidence that Mr. Bolsonaro’s opponents encouraged schoolchildren to become gay or reconsider their gender identity by employing sex education materials referred to as “gay kits.”
“I like what Bolsonaro stands for,” said Cintia Puerta, 55, an architect in São Paulo, said Sunday after voting. “My sister works in a school so I know they are teaching ‘gay kits’ to children, teaching them about sexuality at age 5 and 6. They’re indoctrinating children in the school.”
Mr. Bolsonaro’s presidential ambition nearly ended on Sept. 6 when a man sliced a knife into his stomach during a campaign rally, slashing his intestines and several other organs.
After that, Mr. Bolsonaro declined to participate in debates and did few probing interviews, leaving significant gaps in the electorate’s understanding of his position on pivotal issues, including pension reform and the privatization of state enterprises.
In the wake of the attack, Mr. Bolsonaro’s standing in the polls rose steadily after languishing in the low 20-percent range for weeks. Last-minute endorsements from the influential evangelical lobby and agribusiness leaders gave him a boost.
After the first round of voting, in which Mr. Bolsonaro received just shy of the 50 percent required to win outright, some political analysts expected him to moderate his rhetoric in order to appeal to centrist or undecided voters.
They were wrong.
Last Sunday, he issued a threat to members of the Workers’ Party that critics called downright fascist.
“Those red good-for-nothings will be banished from the homeland,” he said during an address, delivered via a video linkup, to thousands of supporters gathered in São Paulo. “It will be a cleanup the likes of which has never been seen in Brazilian history.”
For the Workers’ Party, Sunday’s presidential defeat leaves a political movement that won accolades from much of the population for affirmative action and inequality-reducing policies significantly weakened and effectively leaderless.
Party luminaries hoped that Mr. da Silva, a lion of Latin America’s left known as Lula, would return to the presidential palace. Even after Mr. da Silva was jailed, party leaders said that “an election without Lula is fraud.”
When courts made clear Mr. da Silva would not be allowed to run, and the Workers’ Party nominated Mr. Haddad, a former education minister and mayor of São Paulo, the campaign’s slogan was “Haddad is Lula.”
During his campaign, Mr. Haddad visited Mr. da Silva in prison multiple times, and did little to take responsibility for the party’s mistakes. This lack of atonement pushed many hesitant Brazilians toward Mr. Bolsonaro, said Mr. Mainwaring, the Harvard professor.
“The Workers’ Party strategy was centered too much around Lula and too little around thinking about the future of the country and about winning this election,” he said. “An important part of the Brazilian electorate would have voted for the P.T. if it had drawn a line in the sand and renounced the corruption of the past.”