Former president Lula wins knife-edge election in Brazil