Early on, incumbent Dilma Rousseff had been expected to win outright.
However, the death of one of the main candidates and the popularity of his replacement, environmentalist Marina Silva, means the vote is now likely go to a second round.
Ms Rousseff’s other main rival is Aecio Neves, a centrist, pro-business figure.
Voting began at 0800 (11:00 GMT) and ended at 22:00 GMT. Voters also selected a federal parliament and state governors.
Mr Neves was narrowly ahead of Ms Silva, according to several opinion polls published on Saturday, which all put Ms Rousseff in a commanding lead with about 45%.
Brazil’s voting system is all electronic and is likely to deliver a result within an hour or two after the voting ended.
On the eve of the vote, the Superior Electoral Court moved to dismissed reports that the system was vulnerable to hacking, saying it was “fraud-proof”, despite frequent attempts to hack into the ballots.
Wyre Davies, BBC News, Rio de JaneiroFor all the daily frustrations with red tape and bureaucracy in Brazil, voting and elections are – for the most part – a model of order and efficiency.
“Business” was brisk at the voting station I went to – a school in the Humaita district of Rio de Janeiro. People of all ages waited patiently but had to queue for no more than half an hour to cast their vote.
In this relatively middle-class part of Rio, the overwhelming sentiment was concern about the worsening economy in a country that has become used to better living conditions and opportunities in recent years.
So while the word “change” was on the lips of many voters, others said they were reluctant to vote against a government that has helped to achieve impressive levels of social mobility in the last decade.
During Ms Rousseff’s tenure as president, unemployment has been lower than under any of her predecessors, at about 5%. The minimum wage has risen and the number of undernourished Brazilians has been falling.
But the past 18 months have been marred by recession and corruption scandals, and protests over poor public services and the World Cup costs.
Despite widespread dissatisfaction with Ms Rousseff’s centre-left Workers’ Party (PT), polls early in the campaign suggested she was well ahead of her leading rivals – who were then Mr Neves and Socialist Eduardo Campos.
But then Mr Campos died in a plane crash and his replacement, Ms Silva, emerged as a surprisingly strong contender.
However, the former minister and environmental campaigner has lost ground in recent days.
Most analysts expect no clear winner to emerge in the first round. This mean the top two candidates are likely to face each other in a second round on 26 October.
Voting is mandatory for those aged between 18 and 70.