Luiz Inácio Lula da Silva has won a fourth term as Brazil's president, defeating right-wing challenger Flávio Bolsonaro.