Brazil’s president Dilma Rousseff was on course for victory in a first-round presidential election on Sunday night, but may well need a second round in three weeks’ time to secure a second term in office.

All indications in the runup to the poll were that Rousseff would secure more than 40% of the vote. The race for second place – and the right to challenge her in a runoff – was too close to call before the publication of official results.

As the nation’s 143 million voters went to the polls, the front pages of almost every newspaper reported that the former environment minister Marina Silva, who was the frontrunner at one stage, had fallen into third place with 24% behind the pro-business Social Democratic party candidate Aécio Neves, with 27%.

While the gap between the two is within the margin of error, the surprisingly steep decline of Silva’s vote in recent weeks underscores the volatility of public opinion during one of the most dramatic campaigns in recent memory.

Initial reports suggested voting was peaceful and orderly. Television channels broadcast images of the candidates going to the ballot box with all of the three main contenders expressing confidence that they would be victorious.

Silva posted images of her in a campaign van on the way to a polling station in her home state of Acre, in the Amazon. “Bring on the second round. Have the courage to change Brazil,” she wrote.

Buoyed by a last-minute surge, the Neves team appeared to put more campaigners on the streets outside the polling stations. Every car had at least Neves two pamphlets under their windscreen wipers and part-time staff handed out cards to every passerby willing to take one.

The Social Democratic candidate tweeted images of himself voting with his wife and a repeated call for votes to push him into a runoff.

“This is how the dreams of Brazil can be realised,” he wrote. “I have great faith and great respect, but I’m ready to get to the second round and to govern Brazil”.

The president’s campaign team tried to mobilise voters through social network blitzes.

“We have carried out a peaceful social revolution over the past 12 years to diminish longstanding social inequality in Brazil,” tweeted Rousseff in a reference to the three consecutive terms of Workers’ party presidents. “We took the hunger map of Brazil made by the United Nations and we lifted billions of Brazilians to university. To complete that, we are now preparing Brazil of a new cycle of even more profound change.”

With more television time and campaign funds, Rousseff’s centre-left Workers’ party and Neves’ centre-right Social Democratic party have focused their attacks on Silva, who has promised to break the decades-old stranglehold of the two main parties with a focus on sustainable development.

Early in the campaign, Silva benefited from outsider status and sympathy after the death of her running mate Eduardo Campos in a plane crash. But, as the vote approached, the debate became less about emotions, change and personality and more about traditional left-right economic policies.

Dilma has solid backing from benefactors of the Bolsa Família poverty relief programme, which covers more than a fifth of voters, and Aécio is the first choice of business.

At the polling station in the Colégio Angelorum school in Gloria, Rio de Janeiro, several voters acknowledged that their opinions had shifted away from Silva in recent weeks.

“I was going to vote for Marina, but she was terrible in the debates. She looked very confused,” said Aline Blajchman, a community care worker who said she was supporting the Green candidate Eduardo Jorge.

Of the dozen or so people approached by the Guardian, a majority said they would vote for Neves, who has benefited from a strong performance in the televised debates and the country’s biggest campaign machine.

“He is the most capable and knowledgeable of the three candidates – the safest pair of hands,” said Silvana Cutrim, a shopkeeper. “Dilma is just an agitator and Marina is too unreliable.”

Others expressed dissatisfaction with all three of the leading candidates, but – with voting obligatory under Brazilian law – said they would opt for continuity.

“I will vote for Dilma. She’s bad, but the other candidates are worse,” said Jaime Souza, a vegetable stall holder.

The election is one of the world’s great exercises in democracy with 450,000 polling stations stretching from the Atlantic seaboard to deep inside the Amazon rainforest.

As well as choosing from the 11 presidential candidates, voters are selecting 27 state governors, 513 congressmen, 1,069 regional lawmakers and a third of the senate.

With voting carried out by machine, the results are expected within a few hours of the close of the polls. The second round will take place on 26 October if the winning candidate does not secure 50% of the vote.