Two polling stations were set on fire in suspected arson attacks - one outside the capital, Antananarivo, and the other in the north-west of the island, the BBC's Tim Healy reports.

On Thursday night, a district chief died in an attack on a polling station in the south-western town of Benenitra, he says.

The two front-runners, Hery Martial Rakotoarimanana Rajaonarimampianina and Richard Jean-Louis Robinson, are both pledging to rebuild Madagascar's economy.

More than 92% of the country's 21 million people live on less than $2 (£1.2) a day, according to the World Bank.

President Andry Rajoelina ousted Marc Ravalomanana from power in 2009, plunging the island nation into political turmoil and leaving the country isolated by the international community and deprived of foreign aid.

'Return to constitutional order'

After seizing power, Mr Rajoelina announced that there would be a new constitution and elections within 24 months.

In May 2009 it was agreed that all former presidents would be allowed to stand in the election. However, these failed to take place in 2009 or 2010.

After casting his vote in Antananarivo, Mr Rajoelina said that it was time Madagascar "returned to the constitutional order", the Associated Press news agency reports.

"The crisis has lasted too long,'' he is quoted as saying.

In January this year Mr Rajoelina and Mr Ravalomanana both agreed not to stand in the polls, in line with a plan by the Southern African Development Community (SADC), a regional bloc that Madagascar belongs to.

The first round of this election was set to take place in July 2013 but was pushed back to August because Mr Ravalomanana's wife and former first lady, Lalao - and then Mr Rajoelina himself - decided to run, prompting donors to suspend financing for the poll.

Mr Rajoelina and Lalao Ravalomanana were then barred from standing and the electoral court also struck former President Didier Ratsiraka from the list of candidates after the three refused to withdraw.

The African Union had said it would not recognise the results if any of the three were declared the winner.

The electoral commission then set the elections for 25 October.

Polls closed at 14:00 GMT and those still in queues were allowed to vote, our correspondent says.

Results must be published by 4 November, but results are expected within 48 hours and a run-off is likely, he says.

If no candidate receives more than 50% of the votes cast, a second round will be held on 20 December, along with the parliamentary elections.

Mr Rajaonarimampianina, a former finance minister in the transitional government, says he aims to help the unemployed, build infrastructure to improve agriculture, reform the education system and make Madagascar a strong democracy.

Mr Robinson says that his electoral programme will draw heavily on a new version of Mr Ravalomanana's Madagascar Action Plan (MAP) to help rebuild society and also rejuvenate the ailing tourism industry.

The polls are being organised by the Independent National Electoral Commission of the Transition (Cenit) - an independent electoral body funded by the United Nations.

Cenit says there are 7,697,382 registered voters and 20,115 polling stations in Madagascar, a country the size of France with a scattered population.