Luiz Inácio Lula da Silva has won a fourth term as Brazil's president, coming from behind to beat Senator Flávio Bolsonaro in a runoff that split the country almost evenly.

Lula took 51.8% of valid votes to Bolsonaro's 48.2%, according to the Superior Electoral Court.