It's the presidential election that just keeps surprising.

A year after a spasm of huge anti-government protests across Brazil, President Dilma Rousseff piled up more votes in Sunday's election than any challenger, but it wasn't enough to avoid a runoff in three weeks.

The race kept up its unpredictable nature as Aecio Neves, a center-right former governor and senator with deep political lineage, came in second. He had languished in the polls during the campaign but surged in the past week to overtake former environment minister Marina Silva, who at one time was the front-runner.

In late August, Silva held a double-digit lead over the field after only entering the race following the death of her Socialist Party's initial candidate in a plane crash. But then her reputation and credentials were picked apart by aggressive campaigning from Rousseff's long-governing Workers' Party.

With nearly all the votes counted, the president had 41.5 percent to Neves' 33.6 percent. Silva got 21 percent.

The Oct. 26 runoff will now pit the candidates of Brazil's two most powerful parties, which together have produced all of Brazil's presidents the past 20 years and are well known to Brazilians.

Neves is backed by the well-organized Social Democracy Party, which held the presidency from 1994 until 2002, a period when Brazil tamed hyperinflation and turned the economy around.

"Aecio's performance has been extraordinary, and one of the reasons for this is the very strong party structure behind him — a party with a strong nationwide presence and which has been in the presidency," said Carlos Pereira, a political analyst at the Gertulio Vargas Foundation, Brazil's leading think tank. "It is now a new election where everything is wide open. Aecio, who until recently no one believed had a chance, has emerged as a very strong candidate."

Neves is an economist and former two-term governor of Minas Gerais, Brazil's second-most populous state, where he left office in 2010 with an approval rating above 90 percent.

He has strong name recognition in Brazil as the grandson of Tancredo Neves, a widely beloved figure who was chosen to become Brazil's first post-dictatorship president but fell ill and died before taking office.

Neves emphasized those roots in a statement Sunday night.

"What I can say, what comes to mind, is what my grandfather Tancredo said 30 years ago when he won the elections for president of the republic: 'We must not get dispersed. We are just in the middle of our path.' And I hope to be able to walk alongside every Brazilian who wants a dignified and efficient government to the end," said the 54-year-old politician, who also has served four terms as a congressman and one as a senator.

Rousseff's aggressive campaigning proved the downfall for Silva, who had been thought poised to tap into the widespread disdain Brazilians hold for the political class — anger that boiled over into last year's roiling protests. But Silva couldn't withstand the president's barrage of attacks labeling her as indecisive and without the mettle needed to lead the globe's fifth-largest nation.

"Marina Silva tried but was not able to convey her message of change. She's only responding to attacks," said Paulo Sotero, director of the Brazil Institute at the Woodrow Wilson International Center for Scholars in Washington. "We've seen negative campaigning before, but never at this level of ferocity."

During nearly 12 years in power, the Workers' Party has ushered in strong social programs that have helped lift millions out of poverty and into the middle class. Rousseff's strongest support comes from the poorest, those who are precariously hanging onto gains amid an economy that has sputtered the past four years.

In contrast to Neves' call for more centrist economic approaches, Rousseff promised in her campaign to expand social programs and continue strong state involvement in the economy, a stand that has drawn criticism from the business sector.

"I feel strongly I received a message, a simple message saying I must continue moving forward ... to change Brazil," Rousseff told a crowd of supporters late Sunday.

___

Associated Press writers Brad Brooks and Jenny Barchfield reported this story in Rio de Janeiro and AP writer Stan Lehman reported from Sao Paulo.

___

Brad Brooks on Twitter: www.twitter.com/bradleybrooks