By Steve Kingstone
BBC News, Sao Paulo
Geraldo Alckmin is the former governor of Sao Paulo
All other things being equal, this election should have been over by now.
For weeks, President Luiz Inacio Lula da Silva enjoyed a huge poll lead, which signalled
a comfortable win in Sunday's first round of voting.
During the campaign he was genuinely able to boast of low inflation, rising wages and falling poverty.
But in a remarkable last-minute turnaround, Lula fell short of the 50% that would have secured outright victory.
Now, he faces an uncertain second phase of campaigning against an opponent oozing momentum.
Friend and foe alike would agree that the election hinged on the "dossier affair", in which Lula's Workers Party (PT) was accused of trying to spend $800,000 on a dossier of corruption allegations against political rivals, including the president's main challenger, Geraldo Alckmin.
The cash was seized when the police arrested two men with links to the PT on 15 September.
Newspapers printed front-page photographs of the haul - the origins of which have not been explained by the party.
Although President Lula moved quickly to contain the damage by sacking his campaign manager, the affair heralded a dip in his commanding poll lead.
Brazil's electoral court opened an investigation, and last Thursday Lula chose not appear in a final televised debate between the candidates.
In retrospect, that looks to have been a huge tactical error, for it was only after the debate that Lula's support
sank below the crucial 50% threshold.
The PT has grumbled of a conspiracy between the opposition, the media and even the police, who it appears may have passed the photographs of the seized cash to journalists.
Lula is popular with poorer voters because of his welfare programmes
But the brutal truth is that, as the campaign moved into stoppage time, the PT scored several spectacular own goals.
Just as memories were fading of last year's cash-for-votes scandal, the party single-handedly revived corruption as a campaign issue.
And by not showing up for the debate, Lula compounded impressions of a governing party unwilling to account for its actions.
In stark contrast to Lula, Mr Alckmin will rightly view Sunday's result as a triumph.
Few commentators had given him much chance of pushing the contest to a second round, but his showing of 41.6% puts him within striking distance of the president.
During the campaign, Mr Alckmin was criticised for being professorial and a little wooden, but with the corruption claims flying, his calm demeanour may have become an asset - reassuring an electorate tired of political fast-talkers.
Mr Alckmin's main support came from Brazil's more prosperous southern states and the central farm belt. In Sao Paulo, the most populous state, he trounced Lula - winning 54% to the president's 36%.
The challenge now is to broaden his appeal in Brazil's impoverished north-east, where voters overwhelmingly backed the president.
Mr Alckmin must also galvanise support within his intrigue-ridden Brazilian Social Democratic Party, where heavyweight figures had already been looking ahead to the next election in 2010.
As the campaign moves into a second and decisive phase, three factors are sure to influence the result.
First, the TSE will continue its investigation into the dossier affair. If Lula is quickly exonerated, he can move forward with his head held high; if not, the scandal will remain the biggest obstacle to his re-election
Second, bear in mind that 10% of the electorate did not vote for either Lula or Mr Alckmin, so both men will seek the endorsement of other, defeated first-round candidates.
Third and fourth-placed respectively were Heloisa Helena and Cristovam Buarque, both of whom are former members of the PT. But their support for Lula is by no means guaranteed.
Finally, there will be more television debates, and this time Lula will not leave an empty chair to represent him.
In a country where candidates' personal appeal to voters really counts, television can make or break elections.
Brazilians will rightly expect to see both men debating this country's future head-to-head.