Ghana's presidential election has been won by incumbent John Mahama, the electoral commission has announced.
It said Mr Mahama had secured 50.7% of votes, with opposition leader Nana Akufo-Addo on 47.74%.
However, the opposition NPP says it will contest the result, accusing the governing NDC party of conspiring with commission staff to fix Friday's poll.
Ghana, one of the world's fastest-growing economies, is regarded as one of Africa's most stable democracies.
The election was declared free and fair by the regional body, the Economic Community of West African States (Ecowas) and a local group, the Coalition of Domestic Election Observers (CODEO).
"There were hiccups but not such that would grossly undermine the result of the election," said former Nigerian President Olusegun Obasanjo, who led the Ecowas observer team to Ghana, AP news agency reports.
In a statement, CODEO said the result was a "generally accurate reflection" of the support of Mr Mahama and Mr Akufo-Addo.
"CODEO advises all the presidential election contestants and their supporters as well as the general public to place confidence in the electoral commission's official presidential election results," it said.
In his first address after being declared the winner, President Mahama urged "all leaders of all political parties to respect the voice of the people".
He added: "The voice of the people is the voice of God."
Police in the capital Accra fired tear gas to disperse opposition protesters from outside the commission's offices on Sunday evening.
Tanks guarded the electoral commission and roads around the offices were barricaded by police as the results were announced.
"Based on the results given, I declare John Dramani Mahama president-elect," electoral commission chief Kwadwo Afari-Gyan told journalists.
He said turnout had been about 80%.
In a statement on Sunday, the opposition said it would contest the results.
"To accept this result is to discredit democracy in Ghana and, in the process, distort the process of democratisation in Africa," the NPP said. "Therefore, the New Patriotic Party cannot accept the results of the presidential election as declared by the EC [election commission] this evening."
Earlier, the NPP said it had "enough concrete evidence" to prove that Mr Akufo-Addo had won the election.
"The ruling NDC conspired with certain EC staff in constituencies across the country to falsify the election results and thereby abuse the mandate of the people of Ghana," the party said.
The party said in a statement on its website that in the northern Savelugu constituency, 31,165 votes had been "falsely declared" for Mr Mahama when he had, in fact, obtained 21,165 votes.
In another case, 15,000 votes were "illegally added" to Mr Mahama's tally in Greater Accra's Dome Kwabenya constituency, it said.
Mr Mahama's presidential adviser Tony Aidoo said the accusations were baseless.
Mr Akufo-Addo lost the 2008 presidential poll by one percentage point, but accepted the result.
Glitches with a new finger-printing system meant that voting continued into Saturday in some parts of the country.
However, observers said the election had passed off largely peacefully.
Mr Mahama was Ghana's vice-president until the unexpected death of President John Atta Mills in July catapulted him into office.