Eduardo Paes, the voluble, samba-dancing former mayor of Rio de Janeiro who presided over its Olympic Games, had expected to win his bid to become governor of Rio de Janeiro state. He had been leading the polls with 27% and was considered to be generally well liked by voters for his affable charm and love of his home city.

But a little-known conservative judge and former marine, Wilson Witzel, raced past him to finish first with 41%, forcing a runoff vote on 28 October.

“Who is Wilson Witzel?” read one headline, a sign of the size of the upset. But voters knew one important thing about Witzel: he is allied to Jair Bolsonaro, the extreme rightwing candidate who was very nearly elected president on Sunday, and he had campaigned with Bolsonaro’s son Flávio, who himself was voted into the Senate.

I hope my fellow Brazilians see through Bolsonaro before it’s too late | Luiza Sauma Read more

Rio’s gubernatorial race was just one of the many upsets in Sunday’s voting for president, Congress and state governments. It was a “conservative tsunami”, said Marcus Melo, a professor of political science at the Federal University of Pernambuco. “This is a very clear reflection of Bolsonaro’s vertiginous rise. This was all over Brazil,” he said.

Facebook Twitter Pinterest Wilson Witzel, seen during a televised debate last month, caused a major upset in Rio de Janeiro state. Photograph: Mauro Pimentel/AFP/Getty Images

Another of Bolsonaro’s sons, Eduardo, was re-elected to the lower house of Congress with 1.8 million votes from São Paulo state, a record tally for a federal deputy. Joice Hasselmann, a former journalist who runs a rightwing YouTube channel with 900,000 followers and who was fighting her first election, received the second most votes in the state with more than 1 million.

Across the country, conservatives allied to Bolsonaro and his tiny Social Liberal party (PSL) won far more votes than anybody had expected. Politicians increasingly grabbed at his coattails as his star rose. The São Paulo mayor, João Doria, allied with Bolsonaro in his race for governor and goes into a runoff vote with a clear lead. It was a smart, if cynical move: his own Social Democracy party (PSDB), traditionally one of Brazil’s big two, lost nearly half its federal deputies. Its candidate for president, Geraldo Alckmin, Doria’s political mentor and a former São Paulo governor, received less than 5% of the vote.

Four years ago the PSL had just one deputy elected. On Sunday it became the second biggest party in the lower house, with 52 deputies – including Luiz Philippe de Orléans e Bragança, a descendant of the royal family that once ruled Brazil, and Alexandre Frota, a former actor in pornographic movies. The party’s president, Gustavo Bebianno Rocha, a lawyer, said on Sunday night that political experts would have to “rewrite everything”, and described himself as a novice in politics. “This is the biggest change we could have in a country that changes very slowly,” Melo said.

Jair Bolsonaro will face the former São Paulo mayor Fernando Haddad, from the leftist Workers’ party (PT), in the runoff vote. Haddad took over the party’s candidacy after its founder, the two-times president Luiz Inácio Lula da Silva, was ruled out because he is serving a prison sentence for graft. The PT party lost some high-profile races.

Lula’s successor as president, Dilma Rousseff, who was removed in 2016 in an impeachment process, failed to get elected to the Senate. Lindbergh Farias, a high-profile PT senator in Rio, failed to get re-elected. Eduardo Suplicy, a popular PT councillor in São Paulo, lost his Senate bid.

Carlos Melo, a professor of political science at the São Paulo business school Insper, noted that the PT continued to be the biggest party in the lower house with 56 seats, five fewer than before. “The PT lost a lot of deputies but still has the biggest caucus,” he said.

Brazilian progressives took heart from other victories. In the Amazon state of Roraima, Joênia Wapixana became Brazil’s first indigenous deputy in decades. In Rio, Marcelo Freixo, a popular leftist from the small Socialism and Freedom party, received the second most votes for federal deputy and three other deputies were elected with him, including Talíria Petrone, who will be one of the few black female lawmakers in Congress.

In neighbouring Espírito Santo state, Fabiano Contarato became Brazil’s first openly gay senator, costing an evangelical pastor and close Bolsonaro ally, Magno Malta, his seat. “The left has not fallen yet,” Melo said.