Dilma Rousseff has been re-elected president of Brazil, after securing more than 51% of votes in the closest election race in many years.
An official count showed her rival, centrist candidate Aecio Neves, taking just over 48% of the vote.
In her victory speech, Ms Rousseff said she wanted to be "a much better president than I have been until now".
She faced protests last year against corruption, record spending on the football World Cup and poor services.
Ms Rousseff, who has been in power since 2010, is popular with poor Brazilians thanks to her government's welfare programmes.
But the vote split Latin America's biggest country almost evenly in two, along lines of social class and geography.
Ms Rousseff called on all Brazilians "to unite in favour of Brazil's future" and said she would seek political reform.
"This president is open to dialogue. This is the top priority of my second mandate," she told a cheering crowd in the capital, Brasilia.