Ghana's President Nana Akufo-Addo narrowly beat his long-time rival John Mahama to win a second term, the electoral commission announced Wednesday, sending thousands of his supporters onto the streets to celebrate.

The West African country is known for its stable democracy, but tensions rose over Monday's presidential and legislative vote after Mahama claimed to have won a parliamentary majority and warned Akufo-Addo against stealing the vote.

John Mahama was president for four years until 2016
John Mahama was president for four years until 2016 AFP / PIUS UTOMI EKPEI

In the presidential race, Akufo-Addo received 51.59 percent of the vote, beating opposition leader and former president Mahama's 47.36 percent, the electoral commission said.

The announcement was greeted with chanting and dancing by a crowd of supporters in the seaside capital Accra.

Ghana
Ghana AFP / Laurence SAUBADU

"Now is the time, irrespective of political affiliations, to unite, join hands and stand shoulder to shoulder," the 76-year-old president told excited supporters honking vuvuzuelas outside his Accra residence.

Observers viewed polling as generally free and fair but police said five people were killed and 19 injured in election-related violence.

The political climate soured late Tuesday when Mahama accused his rival of showing "credentials that are very undemocratic".

Ghana's President Nana Akufo-Addo tells celebrating supporters in Accra that "now is the time to unite"
Ghana's President Nana Akufo-Addo tells celebrating supporters in Accra that "now is the time to unite" AFP / CRISTINA ALDEHUELA

Mahama, 62, charged that Akufo-Addo had harnessed the military in a bid to sway the outcome, a claim the government said was false.

"You cannot use the military to try and overturn some of the results in constituencies that we have won. We will resist any attempts to subvert the sovereign will of the Ghanaian people," the former president said.

The news was greeted with celebrations from his supporters in the seaside capital Accra
The news was greeted with celebrations from his supporters in the seaside capital Accra AFP / CRISTINA ALDEHUELA

Mahama -- who has twice before lost to Akufo-Addo by a narrow margin, the last time in 2016 -- has yet to comment on the results.

The full count of the 275 parliamentary seats has not been announced and are expected to be very close between Akufo-Addo's centre-right New Patriotic Party (NPP) and Mahama's National Democratic Congress (NDC) party.

Soldiers guard the electoral commission, which announced Akufo-Addo's re-election
Soldiers guard the electoral commission, which announced Akufo-Addo's re-election AFP / PIUS UTOMI EKPEI

Ghana has recorded high levels of growth during Akufo-Addo's first term as he worked to diversify an economy largely dependent on cocoa exports and more recently oil and gold.

Supporters of Ghana's President Nana Akufo-Addo gather outside his residence to celebrate his re-election
Supporters of Ghana's President Nana Akufo-Addo gather outside his residence to celebrate his re-election AFPTV / Nipah DENNIS

On education in particular, he is considered to have done well, which matters in a country where 18- to 35-year-olds account for more than half of all eligible voters.

But while Ghana has made large strides in recent years, many still live in extreme poverty with scarce access to clean water or electricity.

"There could be a tendency for an incumbent, who has just secured a second term, to take it easy and relax," Akufo-Addo.

"I am of a different character. I give you my word that I will continue to work very hard to build a prosperous and progressive Ghana, for which we yearn."

Former Ghanaian president John Kufuor was one of the first to congratulate Akufo-Addo, saying on Twitter: "you deserve it."

Ghana has had seven peaceful transitions of power since the return of democracy more than 30 years ago, as post-electoral grievances have always been pursued through the courts -- a rarity in the troubled region.

Hoping to retain that reputation, Akufo-Addo and Mahama on Friday signed a symbolic peace pact, which the 15-nation regional bloc ECOWAS urged "all political parties and their leadership to respect."

The European Union's chief observer Javier Nart said Wednesday that "Ghanaians voted freely".

"While there were isolated violent incidents, both on election day and during the campaign... fears of violence and vigilantism fortunately didn't materialise: they were minor, isolated incidents, some of them tragic," he said.

Despite the coronavirus pandemic, turnout was high, with 13,434,574 people voting -- 79 percent of registered voters.

An urgent task for the next government will be to limit mounting debt and control rising inflation.