Brazilian president Dilma Rousseff has been elected for a second time after winning 51.6% of votes.
The vote, in which opposition leader Aecio Neves won 48.4% support, was the closest since Brazil returned to democracy 30 years ago.
Rousseff said: "I call on all Brazilians, without exceptions, to unite in favor of Brazil's future. I want to be a much better president than I have been until now."
The result means another four years in power for the Workers' Party, which since 2003 has virtually transformed Brazil - lifting 40 million from poverty and reducing unemployment to record lows.