The mayor of the largest city in the Americas was trying to fend off a reelection challenge from the socialist leader of a squatters movement as 57 Brazilian cities held runoff elections on Sunday.

Guilherme Boulos, backed by former President Luiz Inácio Lula da Silva, pushed his way into a surprising runoff with 40-year-old Mayor Bruno Covas.

Covas, the grandson of a former state governor, is a close ally of current Gov. João Doria, his predecessor as mayor, and a strong showing might boost Doria's presidential aspirations for the center-right Social Democracy Party.

He campaigned on his performance leading the city of 12 million people through the COVID-19 pandemic, helping set up field hospitals and pushing for restrictions on activity while challenging President Jair Bolsonaro's dimissal of the disease's seriousness. A cancer survivor, he also recovered from a bout with the virus in June.

Boulos, the son of university professors, decided at age 16 to become a community organizer in poor areas of the city and hasn't left since, still living in a poor neighborhood with his wife and two daughters.

One of the leaders of the Homeless Workers Movement, he became known for organizing invasions of empty buildings in downtown Sao Paulo, arguing they should be shared by homeless families.

He too announced he has tested positive for the new coronavirus.

Unable to vote while quarantining, he appeared on a balcony of his house on Sunday to greet supporters.

Boulos, of the Socialism and Liberty Party, has trailed in the polls, but his emergence has raised hopes by Brazil’s battered left, long led by da Silva, and he drew energetic crowds to his rallies.

“I wanted to vote for a woman and there weren’t any with a decent shot. I will vote for Boulos because he excites people my age," said telemarketing operator Yasmin Menezes, 23. “I don’t have a problem with Mayor Covas, he is decent, but I think Boulos sends a stronger message against sexists and racists.”

Both mayoral candidates oppose President Jair Bolsonaro, whose favored candidate in the mayoral race finished fourth in the first round of voting two weeks ago, with half as many votes as Boulos.

Alberto Bueno, a partner at the consulting firm Concordia, said the socialist candidate might become an important leader even in defeat.

“Boulos managed to win over a young audience and energized leftist anti-Bolsonaro voters," Bueno said, adding, "It will depend on his political skill to project his leadership beyond Sao Paulo.”

The conservative Bolsonaro campaigned for some candidates during his live broadcasts on social media in recent weeks, but few of them won.

The president’s biggest setback, other than Sao Paulo, could come in his hometown of Rio de Janeiro, where polls are pointing to his favored candidate, Mayor Marcelo Crivella, losing to former Mayor Eduardo Paes.

Brazil’s top electoral court has called for social distancing at the polls, where the use of masks is mandatory.

Brazil’s vote is entirely electronic. Final results are expected shortly after polls close at the end of the afternoon. Technology problems at the country’s top electoral court stalled the publication of results in some states for a few hours in the first round, but officials say the issue has been corrected.