Rio De Janeiro — A 63-year old populist renegade rode a wave of voter rage to Brazil’s presidency on Sunday, marking South America’s most dramatic shift to the right since the end of the Cold War-era military dictatorships.

Jair Bolsonaro, a former army captain, bested leftist Fernando Haddad in Sunday’s runoff, winning nearly 56 percent of the vote, according to official results with 92 percent of the ballots tallied. His win adds Latin America’s largest nation to a growing list of countries — from the United States to Hungary to the Philippines — where staunch right-wing nationalists have scored victories at the ballot box.

Bolsonaro ran a Trump-style campaign that made heavy use of social media, and promised to renegotiate the terms of trade deals, put economics before environmental preservation and bring an iron fist to fighting crime. He demonized opponents and polarized the nation with his history of denigrating women, gays and minorities.

“What I most want is to follow the will of God, and the Brazilian constitution,” Bolsonaro said via Facebook Live after winning the race. “We have everything to be a great nation, and if this is the will of God, we will be a great nation.”

Bolsonaro won a first round of the election earlier this month but failed to avoid a runoff. His challenger, Haddad — a one-term mayor of Sao Paulo, Brazil’s largest city — had depicted the election as a fight to preserve democracy. Bolsonaro has been an outspoken defender of Brazil’s former military dictatorship, lamenting that it did not kill enough dissidents.

The election occurred as faith has collapsed in Brazil’s corruption-stained political class, the economy has floundered and gang killings have surged, leaving the nation feeling rudderless and besieged. Haddad ran largely as a stand-in for Luiz Inácio Lula da Silva, the popular former president, whose reelection bid was upended when he landed in jail this year on corruption charges.

“I voted for Bolsonaro because things can’t continue as they are,” said Alexandre Maciel, 44, an asset manager at a financial firm, after casting his ballot in Sao Paulo. “He’s the only one with the courage to do something different.”

Dismissed until recently as an unelectable rabble-rouser, Bolsonaro launched his campaign with no significant political allies, a small party machine and a paltry budget. He overcame those challenges with the power of social media, becoming the first presidential candidate in Brazil to bypass the country’s powerful television networks. He spoke directly to voters through angry all-caps tweets and Facebook Live videos.

His simplistic get-tough solutions to Brazil’s deep-rooted problems of crime and corruption played well online, and he developed a movement that some analysts compared to President Donald Trump’s in 2016. Millions of devoted backers cheered the plain-talking Bolsonaro for articulating their rage. His left-wing opponents, he shouted, should be locked up. Police should use lethal force against criminals.

Even as Bolsonaro was sidelined from the campaign in September — when he was stabbed in the abdomen at a rally — his popularity grew.

Bolsonaro cuts a rare figure in Brazilian politics, which was dominated for most of the past decade and a half by the leftist Workers’ Party. He has been a passionate defender of the dictatorship that ruled the country from 1964 to 1985. He has proclaimed himself a political outsider, despite serving seven terms in congress. For decades, he survived on the fringe, issuing quip after quip denigrating women, gays and people of color.

He once said a female politician was too ugly to rape and suggested that having a dead son was better than a gay son. Last year, he suggested that some descendants of African slaves were fat and lazy.

Bolsonaro has moved toward the mainstream in recent months, celebrating Brazil’s “diversity” in tweets and pledging, “We are going to unite people.”

But he has convinced supporters that he will upend the status quo. To reduce crime, he has advocated that guns laws be relaxed so civilians could fight fire with fire. To spur the economy, indigenous lands and the vast Amazon region should be opened up for development, he has argued.

“It was obvious in this election that someone who could build a credible narrative of being different was going to do well. Bolsonaro understood that,” said Oliver Stuenkel, professor of international relations at the Getulio Vargas Foundation in Sao Paulo. “He was politically incorrect, a bit weird. But that’s one way he has been able to set himself apart from the rest.”

Bolsonaro has campaigned to fix a specific set of domestic woes — corruption, crime, the anemic economy. But some argue that Bolsonaro’s success thus far might not have been possible were this not the age of Trump.

Bolsonaro at times has appeared to mimic the American leader, on whom he has lavished praise. He has promised to make Brazil “great” and picked a war with the media over “fake news.”

“He was trying to look like Trump,” said Marcos Nobre, a Sao Paulo-based political strategist. “His message to the electorate was, ‘If the U.S. elected a Trump, so can Brazil.’“

Bolsonaro grew up a nerdy kid in a large German Italian family with five siblings in Eldorado, a speck of a town in rural northern Sao Paulo state. At a time when the military was torturing, exiling and killing other members of his generation for opposing its policies, Bolsonaro saw the army as his ticket out. At 18, he was accepted to the army’s prep school and later made it to Brazil’s equivalent of the U.S. Military Academy at West Point.

In the army, Bolsonaro developed a reputation for having “excessive financial and economic ambition,” according to military records of the time. In 1986 he was detained for two weeks after publishing an editorial in the prominent national weekly Veja calling for higher salaries for officers.

“He wrote what we were all thinking at the time,” said retired Gen. Paulo Chagas, who served in the military at the same time as Bolsonaro. “It was a difficult economic time for us military men.”

Bolsonaro left the military in 1988 to launch his political career. As a congressman, he frightened peers with his violent rhetoric, calling in 1999 for the assassination of the elected president at the time, Fernando Henrique Cardoso.

“Through voting, nothing will change in this country,” Bolsonaro said at the time in a television interview. “It will only change, unfortunately, on the day a civil war breaks out and does the job that the military regime didn’t do. Killing some 30,000, starting with (Cardoso). Innocent people will die, okay. But in every war, innocents die.”

Though it surged only over the past two months, the Bolsonaro phenomenon began to take off two years ago, observers say. His popularity built in urban areas, where backers became voracious consumers of his missives on Twitter and WhatsApp. It spread to ranchers suffering invasions of squatters on rural farms. White men and wealthy voters, eager to turn the page after a decade of left-wing rule, rallied to Bolsonaro’s side.

His rise caught many people off guard.

A decade ago, Bolsonaro “was like a burlesque spectacle, a clown,” said Rubens Soares, a longtime journalist at Folha de Sao Paulo, one of Brazil’s largest news organizations. “Journalists would walk past his office as he shouted nonsense.”

Yet, Soares said, he noticed a fundamental shift last year. Supporters at Bolsonaro rallies were adoring in a way he’d never seen before in Brazil.

“They would carry him through the streets,” Soares said. “You could tell something was happening.”

As Bolsonaro soared, his candidacy emboldened extremists who, human rights groups say, have staged dozens of attacks in recent weeks on gay men, lesbians, feminists, leftists, journalists and others. If Bolsonaro wins, some fear more political violence. His own rhetoric is often highly inflammatory.

“Let’s sweep these red thugs off the map of Brazil,” Bolsonaro said to cheers at a packed rally on Sao Paulo’s main thoroughfare earlier this month, referring to his leftist opponents. “We are the majority! The real Brazil!”

Long seen as an economic protectionist, Bolsonaro did an about-face during the campaign, embracing the free market. But he still played to nationalists, vilifying China for “buying up” Brazil. Twice divorced and now married to his third wife, he nonetheless proclaimed himself a supporter of family values, and his opposition to gay rights and legalizing abortion helped him win over evangelicals, a powerful voter base.

But corruption and the Workers’ Party were his primary targets. Since democracy was restored here in 1985, two presidents have been impeached, one has gone to jail, and Brazil’s current leader has been indicted on a charge of corruption, a charge he denies. One-third of the lower house is under investigation for corruption, largely tied to a sprawling kickback scheme involving some of the country’s largest companies. Bolsonaro’s outsider-cleans-house platform resonated with Brazilians.

While some Brazilians began to see Bolsonaro as their hero, others seemed to overlook his bombastic statements in a search for meaningful change.

“If there had been another decent candidate, I wouldn’t have voted for him,” Jose Colares, 51, a dentist in São Paulo, said of Bolsonaro after casting his ballot Sunday for the far-right candidate.