Mexico's top electoral court has rejected claims July's presidential election was riddled with fraud.
Whoever is declared winner stands to lead a sharply divided country
The judges said a partial recount of votes had not changed the original result, which gave narrow victory to conservative candidate Felipe Calderon.
Leftist candidate Andres Manuel Lopez Obrador has vowed to continue fighting an outcome he says was rigged.
The judges, whose decisions are final, have until 6 September to formally declare a president-elect.
Mr Calderon noted that the court had not yet confirmed his victory, but said its decision "satisfies me enormously".
"I want to be very cautious... but we are going down a good road," he said.
The BBC's Duncan Kennedy in Mexico City says there is little now to stop Mr Calderon from becoming Mexico's next president and his victory will please Washington.
Fears of a left-wing government on their doorstep, albeit in the benign form of Mr Lopez Obrador, can now be put to rest, he says.
Mr Calderon will be seen as a useful regional counterweight to the likes of Venezuela's fiery anti-American leader, Hugo Chavez, our correspondent adds.
Mr Lopez Obrador refused to accept the court's verdict, and vowed to continue fighting.
"Never more will we accept that an illegal and illegitimate government is installed in our country," he told thousands of supporters in Mexico City.
Mr Lopez Obrador has led mass protests demanding a recount of all 41m ballots cast in July's election.
July's election also chose members of Congress
The electoral court must formally declare the winner by 6 September.
Mr Lopez Obrador's campaign had filed complaints at around 50,000 polling stations, but the court ordered a recount at just 11,839 of them - about 9% of the national total.
The seven judges decided there was no massive fraud and Mr Calderon had attracted a majority of votes.
The judges said there were only marginal changes to the original results because of recounts and annulments.
They said that all parties lost a considerable amount of votes in the rechecking of ballots, but that did not affect the overall result.
The judges' decision is final and there are no appeals.
The ruling clears the way for Mr Calderon to be declared president-elect - but Mexico's political crisis is not yet over, our correspondent reports.
Mr Lopez Obrador has spoken of forming a parallel government to fight what he calls this electoral injustice.
Our correspondent says that is likely to mean a continuation of the massive street protests that have blocked much of the capital during the past month.