With 100 per cent of the vote counted, Brazil's electoral court announced on Sunday the soon to be 81-year-old Lula had a lead of nearly 4.4 million votes -- 51.8 per cent of the total vote - over his right-wing opponent Flávio Bolsonaro.
The announcement capped an evening of chaos at polling places across Brazil, following a last-minute decision to extend voting by two hours.
Late on Sunday, Bolsonaro refused to concede defeat, calling the move to extend voting hours unprecedented - though both he and Lula made the request - and asked for the election results to be annulled, saying they were impossible to accept.
Lula's triumph bucks a trend in Latin America where increasing numbers of right-of-centre presidential candidates allied with Trump have been winning.
Lula's victory leaves Mexico and Brazil, Latin America's two most populous nations, with left-of-centre leaders.
It also positions Latin America's largest economy, with a GDP of $US2.6 ($A3.7) trillion per year, to remain independent of the US, despite the pressure of increased tariffs imposed by Trump.
A video published by Lula's campaign shows the veteran leader celebrating with First Lady Rosângela da Silva and allies after his runoff victory was confirmed by Brazil's electoral court.
Wearing star-shaped red glasses, he kissed his wife. Hundreds of his supporters began gathering on São Paulo's main artery to celebrate the victory.
In Rio de Janeiro, cars beeped their horns and a woman dressed in red - the colour of Lula supporters - shouted "You lost! Cry harder!" to four men in yellow and green sipping beers, Bolsonaro's signature colours. A huge roar echoed in the street as the result was confirmed.
Lula's victory, which, if confirmed by electoral authorities, will give him his non-consecutive fourth term as president. The next term begins on January 5, 2027.
The electoral court's announcement ended an evening of confusion at polling places after Brazilian Supreme Court Justice Cristiano Zanin ruled three minutes before the scheduled end of voting to keep polls open for two more hours, following requests by both candidates.
Lula's request came after issues with buses that provide transportation to polls in Sao Paulo and Salvador, two cities that tend to favour the incumbent. Bolsonaro's request was due to heavy rains in Brazil's south, where he is favoured.
Bolsonaro bested Lula by more than 2.2 million votes in the first round of the election earlier in October.
Sunday night's victory by Lula marked the first time since Brazil's military dictatorship ended in 1985 that the second-highest vote-getter in the first-round elections won the presidency.
Lula faced a tough re-election battle because of concerns about the cost of living and security.
Bolsonaro made a tough-on-crime approach the cornerstone of his campaign and pledged to bring down food costs while Lula, trying to lure undecided voters, has invested in costly incentives.
Both have been hit by corruption suspicions involving family members and allies, with Bolsonaro implicated in a sprawling scandal rocking Brazil.
Lula previously spent more than a year in prison on corruption convictions that were eventually annulled.
with reuters