RIO DE JANEIRO — Brazil’s unpredictable election took another twist Sunday, with leftist President Dilma Rousseff being forced into a runoff race as expected, but against a center-right challenger who only surged in the final week of the campaign.

Rousseff will face Aecio Neves in the Oct. 26 runoff vote, required as no single candidate won an outright majority. With 96 percent of the vote counted, the president had won 41 percent against Neves’ 34 percent.

As surprising as Neves’ rise was the fall from grace of another candidate, former environment minister Marina Silva, who took just 21 percent of the vote. In late August, she held a double-digit lead over Rousseff in polls after being thrust into the race when her Socialist Party’s first candidate died in a plane crash.

But over the past three weeks the powerful political machine of Rousseff’s Workers’ Party eviscerated Silva with what some analysts called the most negative and aggressive campaigning Brazil has seen since returning to democracy nearly 30 years ago. Silva fell hard in polls and could never regain her footing or get her message out.

Neves, however, had the backing of the well-organized Social Democracy Party, which held the presidency from 1994 until 2002, a period when Brazil tamed its hyperinflation and turned its economy around.