Nigeria's President Muhammadu Buhari addresses the 73rd session of the United Nations General Assembly at U.N. headquarters in New York, U.S., September 25, 2018. REUTERS/Carlo Allegri

ABUJA (Reuters) - Nigeria’s ruling party narrowly won a key governorship election in southwestern Osun state, officials said on Friday, suggesting the region that helped sweep President Muhammadu Buhari to power will be hotly contested in national polls early next year.

The poll was a re-run after the first vote, held at the weekend, was deemed by the election commission to be inconclusive because the result was within the margin of error when spoiled ballots were factored in to the count.

The vote had been seen as a test of the ruling party’s popularity in the southwest - a region that helped Buhari win the 2015 election. Its backing for Buhari’s All Progressives Congress (APC), a merger of four regional parties, proved to be crucial in presidential and gubernatorial races.

The APC candidate, Adegboyega Oyetola, was announced the winner by the electoral commission with 255,505 votes compared with 255,023 for the candidate representing the main opposition, the People’s Democratic Party (PDP). It meant the ruling party retains control of Osun.

Buhari plans to seek a second term in the February 2019 presidential election which will be a followed a few weeks later by gubernatorial elections.

“Thank you Osun State for supporting our good governance agenda by re-electing the APC. I assure you that we will continue to work for the progress and prosperity of the state and the nation,” said Buhari, according to a tweet by his spokesman, Garba Shehu.

The PDP rejected the result, saying the election had been marred by voter intimidation.

“What we are witnessing in Osun election is that APC is not ready for free and fair elections in 2019,” Uche Secondus, the PDP’s chairman, told journalists in the capital, Abuja, on Thursday while voting was taking place.

Dozens of lawmakers, including former allies such as the Senate president, have left the ruling party to the opposition in the last few months, threatening Buhari’s hopes of securing a second term in the upcoming presidential poll.