Both sides have alleged vote-rigging, but officials say there is no evidence and observers praised the election.

The run-off was closely watched as Ghana remains a rare example of democracy in West Africa.

Celebration The electoral commission said the results of the run-off showed Mr Atta Mills had won narrowly with 50.23% of the votes, against 49.77% for Mr Akufo-Addo.

"On the basis of the official results given, it is my duty to declare Professor John Evans Atta Mills the president-elect of the Republic of Ghana," the commission's head, Kwado Afari-Gyan, said in the capital, Accra.

He said the commission had considered allegations of vote-rigging by both sides but "did not find the evidence provided sufficient to invalidate the result".

Outgoing President John Kufuor earlier urged both candidates to respect the final result.

He appealed for calm and said any complaints of vote-rigging should be dealt with by the courts after the new president is expected to be sworn in on Wednesday.

Addressing jubilant supporters on the streets of Accra around the NDC headquarters, Mr Atta Mills, who had failed twice before to become president, said: "The time has come to work together to build a better Ghana.

"I assure Ghanaians that I will be president for all." He also congratulated "all other contestants, especially Nana Akufo-Addo, for giving us a good fight."

Although Ghana remains a very divided nation when it comes to choosing a president, it has proved that democracy can work, BBC correspondent Will Ross in Accra says.

Mr Atta Mills, aged 64, is a former vice-president. He lost two previous elections to President Kufuor.

Mr Akufo-Addo, also 64, from the New Patriotic Party (NPP) won the first round of the presidential election but not by enough to avoid the run-off.

There has been no comment from his party on the election result.

Analysts says Ghana's poll could help salvage the tarnished image of constitutional democracy in Africa, after last year's flawed elections in Kenya and Zimbabwe and military coups in Mauritania and Guinea.

The stakes have been raised in these elections because Ghana has just found oil, which is expected to start generating revenue in 2010.