(CNN) -- Opposition candidate John Evans Atta Mills has narrowly won Ghana's presidential election, the Ghana Electoral Commission said on its Web site.
John Atta Mills, left, of the opposition NDC has defeated Nana Akufo-Addo, right, of the ruling NPP in the runoff.
The chairman of the Ghana Electoral Commission, Kwadwo Afari-Gyan, said Mills had garnered about 4,521,032 votes, or about 50.2 percent of the total votes cast.
Nana Addo Dankwa Akufo-Addo, of the incumbent New Patriotic Party, won about 49.77 percent of the total valid votes cast, Afari-Gyan said, according to the commission's Web site.
The two men led a field of eight candidates in the December 7 general election, but neither secured a majority of the votes. Akufo-Addo had held a slight lead in that vote.
The runoff election was so close that it could not be decided until the last of the 230 constituencies, the Tain constituency, voted on Friday.
"On the basis of the official results given, the results of the run-off election in the Tain constituency in the Brong Ahafo Region, which was held on the 2nd January 2009, it is my duty to declare Professor John Evans Atta Mills the President-elect of Ghana," Afari-Gyan said, according to the government's Web site.
Both parties had alleged irregularities in voting in the Ashanti region and Volta regions, but Afari-Gyan said the commission did not find evidence in "purely electoral matters" that invalidated the results.
Mills, 64, will replace John Agyekum Kufuor as Ghana's president on January 7. Kufuor is stepping down after serving two four-year terms, the maximum allowed.
Mills is a law professor who served as vice president from 1997 to 2000 under Jerry Rawlings. He lost to Kufuor in the 2000 and 2004 presidential elections.
Ghana, a country about the size of England, is the world's second-biggest cocoa and gold producer. In 2007, leaders announced the discovery of oil off its shore.
The world recession, however, has hindered growth. Ghana has seen a decline in its exports and will not tap into its oil resources until 2010.
Part of a former British colony, Ghana was among the first African countries to gain independence in 1957. It endured a series of coups before military dictator Rawlings took power in 1981.
A decade later, Rawlings led the country through the transition to a stable democracy with multi-party elections.