Far-right candidate Jair Bolsonaro has won a sweeping victory in Brazil's presidential election.
With almost all of the votes counted, Mr Bolsonaro has 55% of the votes against 45% for Fernando Haddad from the left-wing Workers Party.
Mr Bolsonaro campaigned on a promise to eradicate corruption and to drive down Brazil's high crime levels.
The election campaign has been deeply divisive. Each camp argued that victory for the other could destroy Brazil.
Pointing to the number of former members of the military he surrounds himself with and the nostalgia he has expressed for the era that Brazil was under military rule, his opponents argue that Mr Bolsonaro poses a risk to Brazil's democracy.
But in his victory speech the president-elect said that he would defend "the constitution, democracy and freedom".
"This is not the promise of a party, nor the word of a man. It is an oath before God," he said.
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
Mr Bolsonaro also alienated many Brazilians with his homophobic, racist and misogynistic remarks.
But many of his supporters view him as a "saviour" who will make Brazil safer and who will stand for traditional values such as opposing the legalisation of abortion.
In his victory speech, he also said he would "pacify" Brazil and make it a "great nation again".
Some of his voters celebrated in the street outside Mr Bolsonaro's home in Rio de Janeiro, waving Brazilian flags and letting of fireworks.
One of Mr Bolsonaro's flagship campaign issues has been to increase security for Brazilian citizens. He has portrayed himself as a hardliner who will restore safety to Brazil's streets.
He has indicated that his government will aim to relax laws restricting the ownership and carrying of guns.
His economic policy plans include proposals to reduce government "waste" and promises to reduce state intervention in the economy.
He has suggested that Brazil could pull out of the 2015 Paris Agreement on climate change, arguing that its requirements compromise Brazil's sovereignty over the Amazon region.
Mr Bolsonaro has also said that he will "cleanse" Brazil of corrupt politicians, a campaign promise which has been very popular with Brazilians who say they are tired of the corruption which has seen dozens of high-ranking politicians from the established parties jailed.
The Workers' Party candidate, Fernando Haddad, had tried to distance himself from the corruption scandals which had rocked his party but for many voters that was not enough.
Mr Haddad became the Workers' Party candidate less than a month before the first round of the election after former President Luiz Inácio Lula da Silva was barred from running.
Lula is serving a 12-year prison sentence for corruption.
Mr Bolsonaro will be sworn in on 1 January 2019 and replace outgoing President Michel Temer, who is leaving office with a record low approval rating of 2%.