Mr. Bolsonaro’s rise has stunned Brazilians, some of whom regard him as a symptom of just how troubled the world’s fourth largest democracy has become. A base of fervent supporters, however, views the brash former military officer as the radical solution needed to turn around the fortunes of a nation troubled by soaring violence, an epidemic of graft and an uneven recovery from a prolonged economic recession.
For voters looking for middle ground, the options are limited.
Centrists have struggled for months to prop up a viable moderate candidate, with several establishment figures having been tarnished by corruption scandals.
Outsiders with a plausible shot at the presidency, meanwhile, are wary of taking the reins of a political system many Brazilians regard as rotten to the core.
Mr. da Silva and Mr. Bolsonaro have yet to offer detailed solutions for the most vexing problems the next president will face, including a bloated pension system and endemic violence in several parts of the nation, which the army is increasingly being called upon to quell.
Both men have campaigned in outbursts of anger and indignation, setting a tone for the contest that is largely in line with the national mood.
“You have a sentiment in the country in which people want to throw things overboard,” said Monica de Bolle, a Brazil expert at the Peterson Institute for International Economics.
She compared the high stakes of this year’s campaign to the 1989 election, Brazil’s first direct vote for president after more than two decades of military dictatorship. But in 1989, Ms. de Bolle added, there was a sense of renewal. “Now, people want to destroy,” she said.
Brazilians have had plenty of reason to sour on their political system in recent years.
In 2014, a routine money laundering probe that became known as Lava Jato, or Car Wash, exposed vast kickback schemes that tarred nearly all the large political parties and crippled pillars of the economy, including the state-owned oil company Petrobras, the construction giant Odebrecht and JBS, the world’s largest meatpacker.
As magnates began going to prison, a fate that several veteran politicians implicated in the scandal feared, a coalition of lawmakers in December 2015 set in motion a plan to impeach Ms. Rousseff for tapping into central bank funds to conceal budget shortfalls. Ms. Rousseff decried her removal from office in August 2016 as a “coup,” masterminded by center-right politicians who had failed to attain power through the ballot box.
The political whiplash of the past few years has made Brazilians more discontented with democracy than any other Latin American population, according to a 2017 poll conducted by Latinobarómetro. The survey found that only 13 percent of Brazilians were satisfied with democracy, and that 97 percent felt their government catered to a small, powerful elite.
“Brazilian society is in a critical state,” said Marta Lagos, the head of Latinobarómetro. “People feel abandoned by institutions.”
As a three-judge panel in the southern city of Porto Alegre weighs Mr. da Silva’s appeal, the former president has argued that disqualifying him as a candidate would be a further blow to democracy.
“The truth is that it is the Brazilian people who are being sentenced,” Mr. da Silva told a small group of journalists in São Paulo on Thursday. “The Brazilian people have seen their country lose respect abroad, they are watching unemployment grow, they’re watching as people lose all the labor rights that were won over the past 60 years.”
Workers’ Party officials say Mr. da Silva will appeal for the right to appear on the ballot even if the court upholds his conviction, which by law would technically make him ineligible to run for office. If that fails, it is unclear who would replace him. The Workers’ Party has no other figure with Mr. da Silva’s name recognition and appeal.
Ms. Rousseff, in a separate interview earlier in the week, said she saw the criminal case against Mr. da Silva — who was convicted of accepting $1.5 million in bribes in the form of a refurbished seaside apartment — as the latest effort to disenfranchise Brazilian voters.
“I think it would mark the conclusion of the coup,” she said, reiterating her view that her ouster, while procedurally lawful, trampled the will of the electorate.
Ms. Rousseff said that the men who conspired to topple her had done a dismal job and become ensnared in new corruption scandals. “It just so happens that their candidates and leaders are demolished,” she said, sounding pleased.
That dynamic, she said, has made Mr. Bolsonaro’s candidacy plausible, while also lifting the appeal of Mr. da Silva and the Workers’ Party, which took a hit during the economic recession and from the corruption investigations.
Mr. da Silva kicked off his campaign with a bus tour through the impoverished states in the country’s northeast, where many residents recall his time in office, which coincided with a commodities boom, as the most prosperous in their lives.
Maria de Fatima Oliveira, 53, a part-time assistant at a funeral home in Cansanção, a small town in the state of Bahia, said that without the subsidies she began receiving when Mr. da Silva was president, she could not have paid her electricity and gas bills.
Later, during Ms. Rousseff’s tenure, access to medical care expanded in the area with the arrival of Cuban doctors hired by the government on contracts.
“Here in the northeast, we’re Lula and Dilma supporters,” said Ms. Oliveira, who lives in an adobe house on a dirt road. “All politicians are thieves, but at least when they stole they also gave us back something.”
Mr. Bolsonaro has warned that a return to Workers’ Party rule would put Brazil on a ruinous path, pointing to the crisis in Venezuela as a cautionary tale. He has sought to portray himself as the rare experienced Brazilian politician untainted by corruption scandals, although a recent investigative report by a Brazilian newspaper on his real estate holdings raised questions about how he and his sons could have afforded apartments worth $4.6 million on public service salaries.
A former paratrooper, Mr. Bolsonaro first rattled the political establishment in 1993 when, as a newly elected lawmaker, he called for a return to military rule, saying, “I am in favor of a dictatorship.”
Until recently, Mr. Bolsonaro was largely regarded as a fringe provocateur in Congress with few legislative accomplishments to his name. In 2003, he made headlines for telling a female lawmaker, Maria do Rosário Nunes, that he wouldn’t rape her because she wasn’t worthy of it.
In April, Mr. Bolsonaro stirred outrage again by saying that blacks living in a rural community he had visited “do nothing” and “don’t even manage to procreate anymore.” A federal judge fined him for the remarks, finding they incited racism.
During Ms. Rousseff’s impeachment, Mr. Bolsonaro dedicated his vote to the military officer who tortured the future president when she was a guerrilla leader.
With his eyes set on the presidential palace, Mr. Bolsonaro has promised to empower the security forces to use harsher tactics against criminals, arguing that the police should be allowed to kill more of them.
On his website, Mr. Bolsonaro highlights his advocacy for lowering the age of criminal responsibility, defending the right of citizens to bear arms and promoting what he calls Christian values.
Many Brazilians have watched Mr. Bolsonaro’s rise in the polls with the type of bewilderment Donald Trump’s campaign generated among American political observers. While Mr. da Silva has a commanding 36 percent lead in the latest poll by Datafolha, Mr. Bolsonaro is solidly in second place with 18 percent. The December poll has a 2 percent margin of error.
Mr. Bolsonaro, who is not backed by a powerful political party, has developed a loyal following among young men and wealthy rural Brazilians. Roberto Folley Coelho, who owns a farm in Mato Grosso do Sul, said that while Mr. Bolsonaro can be crude, he is precisely the type of leader Brazil needs now.
“The main thing is honesty,” he said. “He has been in politics for 20 years and has had many chances of becoming corrupt, and yet he is not.”
While the candidate’s disparagement of women and gays has caused consternation, it is in line with the views of many Brazilians, Mr. Coelho said, adding that Mr. Bolsonaro’s tough talk on security appealed to him.
“Our Constitution from 1988 gave too many rights to criminals — at the expense of people’s safety,” Mr. Coelho said.