Far-right politician Jair Bolsonaro has won a sweeping victory in Brazil's presidential election.
The former army captain won 55.2% of the vote against 44.8% for Fernando Haddad of the left-wing Workers' Party.
Mr Bolsonaro's pledge to fight crime and corruption following a string of scandals have won him mass support.
However critics are worried by his praise of Brazil's former dictatorship, and by his comments on race, women and homosexuality.
In one infamous incident in 2015 he told a fellow lawmaker she was too ugly to rape.
Mr Bolsonaro's controversial comments, his pro-gun stance and his populist approach to politics have led to some media dubbing him "Trump of the Tropics".
President Trump himself took to Twitter on Monday to praise the Brazilian president-elect.
For his supporters, Mr Bolsonaro is a politician who they say will bring much needed change to the country – a swing to the right after four elections won by the left.
For the past four years, Brazil has been consumed by a criminal investigation – known as Operation Car Wash – that has uncovered massive corruption.
Dozens of business and political leaders have been jailed. Among them was former President Luiz Inácio Lula da Silva, who was barred from standing in the election.
How did the result break down?
Sorry, your browser cannot display this content.
Presidential Election Results
% valid votes, excluding blank and invalid votes
Click on the states for more detailed results
Who is Bolsonaro and what is he likely to do in office?
The 63-year-old leads the Social Liberal Party (PSL), an anti-establishment group that combines social conservatism and pro-market policies.
Mr Bolsonaro is a deeply polarising figure who has had a divisive effect on Brazilians with both supporters and opponents taking to the streets to make their voices heard.
He has in the past defended the killing of opponents to the country's former military regime and said he is "in favour of dictatorship".
But after the results came in, he told supporters he would be a "defender of democracy" and uphold the constitution.
One of his flagship policies is to restore security by relaxing gun laws and suggested that "every honest citizens" should be able to own a gun.
He has promised to reduce state intervention in the economy and indicated that Brazil could pull out of the 2015 Paris Agreement on climate change.
He takes over on 1 January 2019.
Analysis by BBC's Katy Watson in Sao Paulo
Is there a chance Mr Bolsonaro could soften his stance, now he's won power? Few experts believe it. You only need to look to another firebrand in the continent for guidance.
"The things that Donald Trump outlined and the signals that he gave during the campaign he carried through with," says Kyle Pope of the Columbia Journalism Review, who has studied parallels between Brazil's new president and the leader of the US.
Many say a comparison with Mr Trump is inaccurate. Instead, they say Mr Bolsonaro is more akin to Rodrigo Duterte of the Philippines.
Whatever the comparison, what is clear is that country's sharp swing to the right will resonate beyond Brazil as another populist takes power.
And the opposition will redouble efforts not to take away the gains that country's made since it returned to democracy 30 years ago.
The future looks messy for Brazil.
Does Mr Bolsonaro have backing in Congress?
Yes and no.
On the one hand, his PSL party achieved a remarkable breakthrough in this month's legislative election, increasing its representation from one to 52 seats in the lower house.
However Mr Haddad's PT remains the largest party, with 56 seats.
But most ominously for Mr Bolsonaro, there will be a record 30 parties represented in the next Congress.
This suggest that finding backing for legislation could be difficult for the new president.
What about reaction from outside Brazil?
A number of Latin American leaders congratulated Mr Bolsonaro:
- Argentine President Mauricio Macri described the poll results as Mr Bolsonaro's "triumph"
- Chilean President Sebastián Piñera congratulated Brazilians for a "clean and democratic election"
- Colombia's Ivan Duque welcomed the result and called for the two countries' "brotherly relations" to be strengthened further
- Mexican outgoing President President Enrique Peña Nieto hailed Brazil's "democratic strength"
- Peru's Martin Vizcarra wished Mr Bolsonaro "full success"
- Venezuela's Nicolás Maduro extended his "congratulations to the people of Brazil"
Amnesty International said that taking into account his campaign pledges, Mr Bolsonaro's victory could pose a "huge risk" to Brazil's indigenous peoples, LGBT communities, black youth, women, activists and civil society organisations.