SÃO PAULO, Brazil  Dilma Rousseff was leading late Sunday in her bid to be Brazil’s first female president, but election officials said she had failed to come up with enough votes to avoid a second round.

With about 99.6 percent of the votes counted, Ms. Rousseff, the former chief of staff of President Luiz Inácio Lula da Silva, had 46.8 percent of the votes to 32.6 percent for her closest rival, the former governor of São Paulo, José Serra. Ms. Rousseff needs to exceed 50 percent of the vote total to win outright.

With Ms. Rousseff coming up short, the election will now be decided with an Oct. 31 runoff. Ms. Rousseff was denied her victory by a strong showing by a third candidate, Marina Silva, the Green Party candidate and a former environmental minister, who captured more than 19 percent.

Analysts expressed little doubt that Ms. Rousseff, 62, would prevail in a second round against Mr. Serra. Despite her lack of political experience and public charm, she has ridden a wave of prosperity and good feeling in Brazil under the leadership of Mr. da Silva, whose approval ratings hover near 80 percent.