Luiz Inacio Lula da Silva, who rose from poverty to Brazil's presidency before crashing into disgrace in a corruption scandal, made a spectacular comeback as leader of Latin America's biggest economy at the age of 77.
Lula, as he is affectionately known, scraped ahead of far-right incumbent Jair Bolsonaro to win a third term at the helm, election authorities confirmed.
Just 18 months ago, the bearded leftist hero with the trademark raspy voice was a political pariah, imprisoned in a corruption scandal that divided the nation.
Disgust with his Workers' Party (PT) propelled Bolsonaro into office in 2018, however the vitriolic and divisive conservative quickly lost popularity as he oversaw Covid-19 carnage, environmental destruction, and made comments criticized as racist, sexist and homophobic.
"We need to fix this country... so the Brazilian people can smile again," Lula said during a tireless campaign in which he crisscrossed the country and appeared on popular podcasts to lure younger voters.
He vowed that under his rule, Brazilians will be able to get back to "eating picanha and drinking beer" on the weekends, referring to the popular cut of beef that high inflation put out of reach for many.
The comments reveal the renowned political skill and folksy touch that endeared him to many across the globe, with Barack Obama once dubbing him "the most popular politician on Earth."
The charismatic Lula was the slight favorite throughout a lengthy and polarizing election campaign.
However the election came down to the wire, with Bolsonaro snapping at his heels until the last.
Fall from grace
Lula left office in 2010 as a blue-collar hero who presided over a commodity-fueled economic boom that helped lift 30 million people out of poverty.
Despite fears at the time that his brand of leftism would be too radical, Lula's 2003-2010 administration mixed trailblazing social programs with market-friendly economic policy.
He gained a reputation as a moderate and pragmatic leader.
Lula also turned Brazil into a key player on the international stage, helping secure it the 2014 World Cup and the 2016 Olympics in Rio de Janeiro.
At the end of his time in office, his approval rating stood at an unprecedented 87 percent.
But he then became mired in a massive corruption scandal centered on state-run oil company Petrobras that engulfed some of Brazil's most influential politicians, business executives and the PT.
Lula has always denied the accusations that he received kickbacks for giving out access to juicy Petrobras contracts.
He was jailed in 2018, the year Bolsonaro won. He spent more than 18 months in prison before being freed pending appeal.
His convictions were thrown out last year by the Supreme Court, which found the lead judge on the case was biased.
However, he was not exonerated. Many Brazilians remain traumatized by the scale of the corruption scandal. While many others have fond memories of economic prosperity under his rule, others voted for him merely to see the back of Bolsonaro.
From poverty to president
Lula grew up in deep poverty, the seventh of eight children born to a family of illiterate farmers in the arid northeastern state of Pernambuco.
When he was seven, his family joined a wave of migration to the industrial heartland of Sao Paulo.
Lula worked as a shoeshine boy and peanut vendor before becoming a metalworker at the tender age of 14.
In the 1960s, he lost a finger in a workplace accident.
He rose quickly to become head of his trade union, and led major strikes in the 1970s that challenged the then-military dictatorship.
In 1980, he co-founded the Workers' Party, standing as its candidate for president nine years later.
Lula lost three presidential bids from 1989 to 1998, finally succeeding in 2002 and again four years later.
This was his sixth presidential campaign.
The twice-widowed father of five survived throat cancer and in 2017 lost his wife of four decades, Marisa Leticia Rocco, to a stroke.
Lula has said he is again "in love as if I were 20 years old" with Rosangela "Janja" da Silva, a sociologist and PT activist whom he married in May.
Lula has said he will not seek a second term.