Brazilians have voted in an election which will decide who leads the world's seventh-largest economy, with opinion polls narrowly favouring the current president, Dilma Rousseff.
About 143 million people are choosing between leftwing incumbent Rousseff and the conservative Aecio Neves, the scion of a famous political family.
Polls gave Rousseff between a four-percent and six-percent lead, although the election remained too close to call.
The winner will face a declining economy in recession and rising inflation which has broken the government's own target ceiling of 6.5 percent.
They will also have to deal with public frustration over shoddy public services and endemic corruption.
"We are voting for a more equal Brazil with more opportunities," Rousseff, the country's first woman president, said as she cast her vote in the southern city of Porto Alegre.
"People are called to choose between two projects. Ours is to ensure Brazil continues to grow with more health and education."
Neves, accompanied by his wife who recently gave him baby twins, meanwhile gave victory signs as he cast his ballot more than two hours after polls opened in Belo Horizonte, capital of Minas Gerais state which he once governed.
"Change has already begun," he said on Twitter.
Gabriel Elizondo, reporting from Belo Horizonte, said: "In a brief interview with journalists before leaving her hotel to vote, Rousseff said the tone of the campaign was regrettable and Neves, after voting, said it was one of the dirtiest elections ever.
The election did get ugly at times with personal attacks on both sides, and it has really divided many Brazilians."
Results are expected shortly after the 8pm GMT close on Sunday, thanks to Brazil's electronic voting system.
Lucia Newman, Latin American editor
Unlike almost every other country in Latin America, sporting electoral propaganda, the colours, face or name of your favourite party or candidate is perfectly legal in Brazil inside polling stations. What you cannot do is utter the canidate's or party´s name out loud - your preference must be expressed in silence.
At the Joao Paulo II School in Brasilia, I saw dozens of people wearing stickers in favor of Aecio Neves and Dilma Rousseff.
A 35-year-old voter told me that he had voted for Rouseff. "I am from a privilaged class but the poor people who need the government's help most have seen their lives improve a lot. Everyone else in my family voted for Aecio, though."
A couple with a four-month-old baby in tow told me they had voted for different candidates."I voted for change", said Maria da Silva, referring to Neves. "I want my constitutional rights to decent public health, medicine and education respected and I feel that this is not the case today."
Her husband disagreed, saying it is a process and change cannot come overnight. This is the argument of the current president, Dilma Rousseff, who has overseen a stagnant economy and high inflation, coupled with serious bribery scandals involvig her Workers' Party.