Image copyright Reuters Image caption Ashraf Ghani (L) and Abdullah Abdullah both claimed victory after polling day in September

Afghan President Ashraf Ghani appears set to win a second term, after preliminary election results showed he was on course to win a narrow majority.

He secured 50.64% of the vote in the September 28 election, officials said. The initial results were delayed amid protests and allegations of fraud.

Mr Ghani's main rival, Dr Abdullah Abdullah, won 39.52% of the vote.

But he has rejected the result and is expected to file an appeal before the final result is announced.

"We would like to make it clear once again... that our team will not accept the result of this fraudulent vote unless our legitimate demands are addressed," a statement from Dr Abdullah's team said on Sunday.

Dr Abdullah disputes about 300,000 votes. An announcement of the final result could take weeks.

In the last presidential election five years ago, Mr Ghani and Dr Abdullah became embroiled in a long-running dispute about the results which caused months of political uncertainty.

The UN, which supported the election process, welcomed the preliminary results and urged the election commission to deal "transparently and thoroughly" with any complaints.

What's the background?

Just days after voters went to the polls, Mr Abdullah and Mr Ghani both declared victory but neither candidate offered evidence in support of their claim.

Preliminary results were expected in October but they were delayed due to technical issues and allegations of fraud.

Turnout was also the lowest it has been since the Taliban were ousted in 2001, with just 1.82m votes counted. Afghanistan's total population stands at about 37 million, with 9.6 million registered voters.

Nearly one million votes were reportedly excluded due to irregularities.

The low turnout is in part attributed to widespread safety concerns as the Taliban had threatened to attack polling stations and targeted election rallies before polling day.

But there was also a perceived lack of enthusiasm ahead of the vote - not helped by the fact the same two men who had fought for months over the top job in 2014 were the front-runners once again.

Both have been accused of corruption while in office. Meanwhile, unemployment stands at about 25%, according to the UN, and almost 55% of Afghans are living below the poverty line.

Why does this election matter?

Whoever wins will lead a country devastated by four decades of war while the conflict continues to kill thousands of people every year.

Media playback is unsupported on your device Media caption Is peace with the Taliban possible?

Talks between the US and the Taliban collapsed after President Donald Trump declared them "dead" in September.

The Taliban refuse to negotiate directly with the Afghan government, saying it is illegitimate. They say they will only talk to Afghan authorities after a deal with the US is agreed.

The US currently has about 13,000 troops in Afghanistan, and there are thousands more from a Nato mission to train, advise and assist the country's own security forces.