Incumbent President Dilma Rousseff narrowly defeated center-right challenger Aecio Neves in a runoff election on Sunday as Brazilian voters gave her center-left Workers' Party a fourth term in the presidency.
Rousseff, who took over from popular predecessor Luiz Inacio Lula da Silva, won by far fewer votes than she did in 2010, and will need to build a coalition with a reduced number of party members in Congress.
With nearly all votes counted, Rousseff had 52% to Neves' 48%.
Lula oversaw an economic boom and the expansion of social programs that lifted tens of millions out of poverty, but growth has buckled under Rousseff, and accusations of corruption have surfaced against her party recently.
The Workers' Party, however, campaigned energetically in the final weeks of one of the most turbulent elections in recent Brazilian history, telling its base of low-income voters that social gains would be best preserved if Rousseff stayed in power.
"She was reelected because the public policies implemented under Lula and Dilma really did improve the lives of the poorest Brazilians," said Francisco Fonseca, a political scientist at the Getulio Vargas Foundation business school in Sao Paulo. "But the election was so close because the rising middle classes just above them are now more conservative."
He added that Rousseff may turn further to the left in her second term, given her base of support. That appeared to be in the minds of some voters.
"I think Dilma will continue to put more focus on opportunities for the poor," said Nathalia Pino Lopes, 23, a bank teller who voted Sunday on the lower middle class outskirts of Sao Paulo. "Things are far from perfect and Aecio seems fine, but I just trust her more to maintain social programs and benefits."
The presidential campaign was upended in August when Socialist Party candidate Eduardo Campos was killed in a plane crash. His environmentalist running mate, Marina Silva, took over and surged to the head of the polls, only to fall back just as quickly after suffering attacks from Rousseff's team, and was beaten out by Neves in first-round polling Oct. 5.
Then, in the final days of the campaign, Brazil's highest circulation magazine, the right-wing Veja, published a special issue with a cover story that accused Lula and Rousseff of knowing about an alleged kickback scheme at state-owned oil company Petrobras, still being investigated by authorities. Rousseff accused the magazine of "electoral terrorism" and took the issue to electoral authorities, who agreed Veja had tried to "disrupt" voting without proof and forced the magazine to print a response from Rousseff's team on its website Sunday.
Neves was more strongly favored by investors and Brazil's educated middle class, whose members often complain of corruption, fears of stagnation and Rousseff's version of economic intervention.
"We need to get the corruption rooted out of government, and we need to get back to growth," said Leonardi Alberti, a 27-year-old civil engineer in Sao Paulo, Brazil's business capital and a bastion of support for Neves. "I would never vote for the left-wing Workers' Party, but I admit Lula's government was good. With Dilma, we took a step back."
Neves was born into political royalty, the grandson of Tancredo Neves, who was elected president but died before taking office. His Social Democracy Party led the country before Lula took over.
Rousseff, a former left-wing guerrilla who was imprisoned and tortured by Brazil's military dictatorship, enjoyed high approval ratings for her first years in office, but saw them drop after more than a million protesters took to the streets demanding better transportation, schools and hospitals last year.
Economists expect the country to barely grow in 2014, though Rousseff often points out that unemployment is still low and wages have continued to rise.
"The changes to our lives since Lula took over were huge," said Cara Almeida de Souza, 34, an accountant and Rousseff voter in Recife, a large city in the poorer northeastern region that overwhelmingly supported Rousseff. "I don't know why we would need to go back to the economic model we had before."