The Brazilian leader secured a historic fourth term in office, pulling off a dramatic comeback after losing the first-round ballot to rightwing challenger Flávio Bolsonaro.