Pakistan's Supreme Court says President Pervez Musharraf can stand for election next week despite still being head of the country's army.
Friday's verdict is a major victory for Gen Musharraf
It dismissed a number of legal challenges to his right to hold both posts at the same time.
Gen Musharraf registered for the forthcoming ballot on Thursday.
The main opposition alliance say it will boycott the poll. The president is chosen by the national parliament and the four provincial assemblies.
Friday's verdict is a serious blow to opposition parties, especially as the Supreme Court has handed down a number of key verdicts against the government in recent years.
2 Oct: Date main opposition alliance to begin boycotting assemblies
06 Oct: Presidential vote to be held, election commission says
18 Oct: Date ex-PM Benazir Bhutto has set for her homecoming
15 Nov: Parliamentary term ends and general election must be held
The BBC's M Ilyas Khan in Karachi says the opposition now has two options. One is to fight another legal battle with the Election Commission against Gen Musharraf's candidacy. The other is to build public pressure against the government to try to prevent his election.
President Musharraf's lawyers have said that if he wins another term of office in the election, scheduled for 6 October, he will resign as army chief in November.
Earlier this week the United States called on Gen Musharraf to ensure the election is free and fair.
He is a key ally in America's so-called war on terror but observers say Washington is worried about his declining popularity and the increasing problems of militancy in the country.
"As per majority six-three, the petitions are not maintainable," the head of the nine-member panel of judges, Rana Bhagwandas, announced.
Opposition parties and most of Pakistan's lawyers have been campaigning to remove Gen Musharraf since he tried to sack the chief justice of the Supreme Court, Iftikhar Chaudhry, in March.
Lawyers outside the Supreme Court received Friday's verdict with a mixture of disbelief and anger.
"We do not accept the decision", Ali Ahmed Kurd, a senior lawyer said, suggesting that it was politically motivated. "This decision has been written in the presidency."
Information Minister Tariq Azeem said: "It is a great victory for the rule of law and supremacy of the constitution... I would now ask everybody, including the opposition, to respect the decision and accept it".
There are more than 40 candidates for the presidential election. None are expected to be a serious challenge to Gen Musharraf.
Earlier on Friday, one candidate, Wajihuddin Ahmad, challenged Gen Musharraf's eligibility to stand with the Election Commission.
Among his objections, Mr Ahmad says that Gen Musharraf has failed to disclose his university qualifications, a mandatory requirement.