With 99.59 percent of the vote counted, Felipe Calderon would win even if all the remaining votes went to Andres Manuel Lopez Obrador of the Democratic Revolution Party. He had 35.83 percent of the vote, compared to 35.36 percent for Lopez Obrador. Just less than 200,000 votes separated them.
Supporters of Lopez Obrador, who promised to govern for Mexico's millions of poor and forgotten, wept in the streets, saying they weren't going to let their leader be robbed of his victory.
At a news conference, Lopez Obrador called on supporters to gather this weekend in Mexico City's center, fueling fears that he would mobilize massive protests that could lead to violence.
Lopez Obrador had led throughout the official count until he was overtaken by Calderon with 97 percent of the vote tallies recorded. Ruling party officials said Lopez Obrador had been ahead only because his people had been stalling the count with protests in Calderon's strongholds.
Once the count is complete, it can be disputed before the country's top electoral court. A winner must be declared by Sept. 6.
Mexico's peso strengthened against the dollar early Thursday after the official tally showed the business friendly Calderon leading.
As the count switched to Calderon's favor before dawn, he called for the country to move beyond the bitter race.
"Starting today, let us help Mexico begin a new era of peace, of reconciliation," he told hundreds of cheering supporters at his campaign headquarters.
He called Sunday's election "the most democratic and cleanest in the history of Mexico," and he asked his rival and all Mexicans to erase the bitter divisions that arose during the lengthy campaign, and focus "not on our differences, but on our similarities."
Before retreating to his home, he turned his remarks to the millions who did not vote for him, asking them "to give me a chance to win your confidence."
Thursday's vote capped four days of debate over the election results.
When polls closed Sunday, citizens staffing the 130,488 polling places opened the ballot boxes and counted the votes, then sealed them into packages with their tallies attached and reported unofficial totals to the IFE. The institute then posted preliminary results on its Web site from about 41 million ballots cast.
Calderon led the preliminary count by one percentage point. As the recount began, the Conservative Party accused the Leftists of trying to trash the election, reported CBS News' Adrienne Bard. The Left had implied the vote count was rigged in some way.
The sealed packages were delivered to district headquarters, where election workers used the tallies to add up the formal, legal vote totals.
Lopez Obrador called for electoral officials to carry out a manual ballot-by-ballot count, instead of just tallying vote totals as they have been doing.
"We are going to the Federal Electoral Tribunal with the same demand, that the votes be counted, because we cannot accept these results," he said.
He criticized electoral officials for rushing to confirm the ruling party's victory, saying they had handled the weeklong dispute poorly.
"We are always going to act in a responsible manner, but at the same time, we have to defend the citizens' will," he said.
He also stoked fears that Mexico was returning to its fraudulent past, in which the ruling party rigged elections in its favor.
"They know very well that they don't have anything to celebrate," he said of the ruling party. "It is all choreographed. There is no joy. They know very well what they did."