Mr. Bolsonaro had claimed for months that the polls were underestimating his support, using his enormous rallies as evidence. Yet, virtually every poll showed him behind. On Sunday, it was clear that he was right. He performed better in all of Brazil’s 27 states than what Ipec, one of Brazil’s biggest polling firms, had predicted a day before the election, exceeding the projections by at least 8 percentage points in 10 states.

Pollsters appeared to misjudge the strength of conservative candidates across the country. Governors and lawmakers supported by Mr. Bolsonaro also outperformed polls, winning many of their races on Sunday.

Cláudio Castro, the right-wing governor of Rio de Janeiro state, was re-elected in a landslide, with 58 percent of votes, 11 percentage points more than Ipec’s projection. At least seven of Mr. Bolsonaro’s former ministers were also elected to Congress, including his former environment minister, who oversaw skyrocketing deforestation in the Amazon, and his former health minister, who was widely criticized for Brazil’s delay in buying vaccines during the pandemic.

Antonio Lavareda, the president of Ipespe, another top polling company, defended his firm’s research, pointing out that it had predicted Mr. da Silva would finish with 49 percent, versus the 48 percent he received.

Yet Ipespe also predicted Mr. Bolsonaro would receive 35 percent of the vote, more than 8 percentage points below his actual support. The poll’s margin of error was 3 percentage points. (That trend played out across the polls; they were nearly accurate on Mr. da Silva’s support, but far off on Mr. Bolsonaro’s.)

Mr. Lavareda speculated that many voters who had said they would vote for less popular candidates had switched to Mr. Bolsonaro — or that they had lied to the pollsters.

Outside Mr. Bolsonaro’s home in a rich, beachside neighborhood in Rio de Janeiro, his supporters gathered to celebrate, dancing and drinking out of plastic cups of beer. Many were wearing the bright yellow jerseys of Brazil’s national soccer team, which has become a sort of uniform for many of Mr. Bolsonaro’s supporters. (The president wore one to vote, over what appeared to be a flak jacket or protective vest.)