Fernando Haddad of Brazil's governing Workers' Party (PT) has been elected mayor of Sao Paulo, the country's biggest city and financial capital.
Mr Haddad, a former education minister, defeated Jose Serra of the Social Democratic Party (PSDB) by 56% to 44%.
Mr Haddad had received vigorous backing from ex-president Lula and President Dilma Rousseff, both of the PT.
The local elections are seen as a test of the parties' strength ahead of the 2014 presidential poll.
From 1994 until 2002, the PSDB held the presidency with Fernando Henrique Cardoso.
Since then the PT has been in the post, first with Lula and from 2010 with President Rousseff.
Mr Haddad, who began his campaign with just 3% support, thanked Lula and President Rousseff for their role in his victory which saw the PSDB lose control of Sao Paulo after eight years.
"We're going to reduce the huge inequality that exists in Sao Paulo. We're simultaneously one of the richest and most unequal cities on the planet," Mr Haddad said.
Sao Paulo, home to 11 million people, is Brazil's financial and business hub, but as a sprawling megacity suffers from chronic traffic congestion, inadequate infrastructure and security problems.
Voting took place on Sunday in cities where no candidate had won an outright majority in the first round on 7 October.
The PT did not enjoy success everywhere, losing by big margins in Salvador and Fortaleza, two of the biggest cities in Brazil's north-east.
In Rio de Janeiro, Eduardo Paes of the Democratic Movement Party (PMDB) was re-elected mayor in the first round and will be in charge during the 2016 Summer Olympics.