Dilma Rousseff of the Workers Party has been re-elected Brazil's president in what was one of the most closely contested elections in the country.