RIO DE JANEIRO — Just as many opponents of Donald Trump considered him unelectable in 2016, detractors of Brazil's President-elect Jair Bolsonaro always believed the far-right candidate himself was the ultimate fail-safe mechanism.
Like Trump, who was caught on video boasting that he grabbed women by the genitals, Bolsonaro came to the race with a long history of comments that were offensive to many people. He twice told a female colleague in Congress she was too ugly to be raped, said a dead son was preferable to a gay one and often disparaged blacks and indigenous people.
The former army captain also frequently cast aspersions on democratic institutions and argued that if the 1964-1985 dictatorship made any mistake, it was that it didn't go far enough in killing communists who threatened the nation.
All of that, the reasoning went, made him simply too toxic for the majority in Brazil, a conservative nation but also one where many people pride themselves on a certain live-and-let-live approach to life.
That belief was so strong that parties across the spectrum never considered a unifying strategy against Bolsonaro. Instead, they jockeyed for position, believing that whoever among the other dozen candidates placed second to Bolsonaro in the first round of voting Oct. 7 would beat him in the runoff Sunday.
The left-wing Workers' Party, which had won the previous four presidential elections, was seen as the best positioned to do that despite its problems — the decimation of its ranks and tarnishing of its image by the huge "Operation Car Wash" corruption investigation involving billions of dollars in bribes to politicians via inflated construction contracts.
Working on the assumption that a Bolsonaro victory was impossible, the party decided its best shot to get to the second round — and thus to victory — was to rely heavily on its standard bearer, former President Luiz Inacio Lula da Silva, even though he began serving a 12-year sentence for corruption in April.
Though it was clear da Silva's candidacy would eventually be barred, he was adored by enough Brazilians to lead preference polls for over a year. The thinking went that the party could appoint a stand-in at the last minute and da Silva's support would just shift to the new candidate. Enter former Sao Paulo Mayor Fernando Haddad, whose central campaign slogan was "Haddad is Lula, Lula is Haddad."
But at no point did the Workers' Party recognize its role in the "Car Wash" scandal. Nor did the party look beyond da Silva. While he is loved by many, he is also widely loathed because of "Car Wash" and a recession under his successor, President Dilma Rousseff, who was removed from office in 2016 for illegally managing the federal budget.
Haddad was not named to replace da Silva until Sept. 11, less than a month before the first round. Still, he outdid the other candidates to finish second with 29 percent of the votes in the first round and earn a spot in the runoff.
Bolsonaro almost won outright, though, getting 46 percent. And Haddad could never make up the ground. Bolsonaro easily won Sunday with just over 55 percent of the votes, compared to just under 45 percent for Haddad.
The Workers' Party and others betting against Bolsonaro underestimated the power of his simple campaign platform and messaging ability, particularly on social media.
His promises, like Trump's, were easy to digest: He would bring the fight to criminals with brute force, clean up corruption by jailing politicians on the take and give the Brazilian economy the kind of tough love it needed via pension reform and privatization.
Perhaps nowhere did Bolsonaro better make his case than during his near-daily Facebook Live sessions. Wearing a T-shirt and sitting at an empty table, he looked into the camera and just talked. For many Brazilians exhausted by stories of politicians plundering public coffers and living lavish lifestyles, the image of a stern and austere father figure ready to bring order to the house was refreshing.
Bolsonaro doubled-down on his social media strategies after he was stabbed and nearly died while campaigning Sept. 6. Within a few days of the attack, he resumed talking to followers via videos and tweets issued from his hospital bed.
"Bolsonaro is the voice of people who want to speak but don't feel they can because they fear being politically incorrect," said Carlos Manhanelli, political marketing specialist and chairman of the Brazilian Association of Political Consultants. "He presents himself as he is, and in the minds of voters that is authentic."
While Trump's victory was a surprise, a Bolsonaro win looked increasingly inevitable the last month.
Perhaps the clearest sign came in late September when anti-Bolsonaro marches organized by women's groups brought tens of thousands to the streets, yet polls soon started saying Bolsonaro's support among women was actually rising steadily.
That trend continued to the point that polls Saturday had him supported by 42 percent of women voters, compared with 41 percent for Haddad.
Valentina Collet, a 48-year-old doctor in Sao Paulo who voted for Bolsonaro, summed up the calculus that many women made.
Bolsonaro "is everything I don't believe in. I'm against violence. I'm against weapons. I'm against his attitude," she said, then added: "We fought so hard to pull the Workers' Party from power. So, in the end are you going to vote the same thing back in?"