Former Brazilian President Luis Inacio Lula da Silva on Sunday defeated incumbent President Jair Bolsonaro in the presidential runoff.
Lula got 50.8 percent of the votes compared with Bolsonaro's 49.2 percent, with 99.1 percent of voting machines counted, which the Supreme Electoral Court said was enough to "mathematically define" the outcome of the race.
This is the smallest difference in a second-round presidential election in Brazil's history.
In the first round held on October 2, Lula obtained 48.3 percent of the vote, compared to 43.2 percent received by Bolsonaro.
Lula focused his campaign on social issues, making pledges including minimum wage increases, strengthening of state-owned companies and efforts against hunger and poverty. He also promised to combat destruction of the Amazon rainforest, now at a 15-year high, and make Brazil a leader in global climate talks.
"Today the only winner is the Brazilian people," 77-year-old Lula said in a speech at a hotel in downtown Sao Paulo.
"This isn't a victory of mine or the Workers' Party, nor the parties that supported me in campaign. It's the victory of a democratic movement that formed above political parties, personal interests and ideologies so that democracy came out victorious," he added.
Voting is electronic and the results were announced within two hours of polling stations closing at 5 p.m. (2000 GMT).
Foreign leaders, including U.S. President Joe Biden, France's Emmanuel Macron and Argentina's Alberto Fernandez, sent Lula messages of congratulations.
Lula will take office on January 1.