Brazil election: Long queues as Brazilians vote in divisive poll
Large numbers of Brazilians have been voting in the most polarised presidential election for many years.
Long queues formed at polling stations across the country, where almost 150 million people are eligible to vote.
If no candidate gets more than 50% of the valid ballots, there will be a second round in three weeks.
Opinion polls suggest far-right candidate Jair Bolsonaro, who has vowed to be tough on crime, is the favourite to secure most votes.
One round or two?
His main rival is the left-wing candidate for the Workers' Party, Fernando Haddad. Both are expected to advance to the run-off on 28 October although Mr Bolsonaro and his supporters have said they think they can get the 50% of the valid votes needed to win outright.
"If God is willing, we'll settle this today," he told reporters. "We are on an upward trajectory and are confident that the Brazilian people want to distance themselves from socialism," the 63-year-old former army captain said.
Mr Haddad, a former mayor of São Paulo, was confident there would be a second round and said he was optimistic he could win it. "The second round is always a renewed opportunity for people to compare the projects," he said.
While opinion polls give Mr Bolsonaro a wide lead over Mr Haddad in this round, the same polls suggest they could be neck and neck in the run-off.
At the scene: South America correspondent Katy Watson
The rain and grey skies make for a pretty grim day here in São Paulo. A metaphor for how people are feeling as they head out to vote.
Standing inside the polling station you can often tell which way people are going to vote - wearing red is a giveaway - a Workers' Party supporter. If it's a Brazilian football shirt or a combination of its colours - yellow, green and blue - then they're likely to be Bolsonaro supporters or at the very least right-wing. And then there are the obvious ones - T-shirts with Bolsonaro's face emblazoned on the front.
There's a lot of anger - anger from those who don't want the Workers' Party back in power or anger over the idea that a far-right candidate could become the next president.
Many of those I've spoken to at the polling station say they are here to make a protest vote. Its more about choosing the least worst option rather than choosing the best.
People here all want change but Brazilians are lost as to these elections can make that to happen.
A former mayor of São Paulo, Mr Haddad is backed by former President Luiz Inácio Lula da Silva, who was disqualified from standing in the election after he was jailed for corruption.
Divisive and eventful
"I'm very hopeful that we will have a much more civilised second round," Mr Haddad said about the deep divisions the campaign had stirred up and which saw a lone attacker stab Mr Bolsonaro.
Mr Bolsonaro, who lost 40% of his blood in the attack. missed the final part of the electoral campaign but saw his popularity rise in recent weeks.
A Catholic who has won the support of many evangelical Christians, Mr Bolsonaro quoted the Bible as he cast his vote. "Our banner was always John 8:32: 'Then you will know the truth, and the truth will set you free'," he said.
Mr Bolsonaro has stirred controversy with racist, homophobic and misogynist comments and there have been mass demonstrations against him.
But his tough stance on crime has won him the support of many Brazilians who feel that record-high crime rates have made them prisoners in their own homes.
On the eve of Sunday's vote, Mr Bolsonaro said his government would hand down the tough punishments offenders deserved. He is in favour of relaxing gun ownership laws and has spoken of torture as a legitimate practice. He also wants to restore the death penalty.
Former Brazilian football star Ronaldinho tweeted his support for Mr Bolsonaro on Sunday, writing that "for a better Brazil, I want peace, security and someone who brings back joy".
Mr Haddad has portrayed himself as a trusted candidate for those who balk at Mr Bolsonaro's style and rhetoric. "I don't believe in violence, in military dictatorship or the lack of liberty," he tweeted.
"We have the ability to defeat what Bolsonaro stands for, in terms of reversing social gains, in terms of civility, in terms of solidarity and in terms of mutual respect," he said.
People have also been casting ballots to elect all Brazil's state governors as well as two-thirds of the senators and all lawmakers in the chamber of deputies.
More than 1,000 seats in state legislatures across the country are also being contested.