Sri Lankan president Mahinda Rajapaksa has conceded defeat in his bid for a third term in office.

Mr Rajapaska has bowed to the people's decision and left Temple Trees, his official residence, said Wijeyanda Herath, his media secretary.

In a result unthinkable just weeks ago, Mr Rajapaksa lost to his former friend and health minister, Maithripala Sirisena, who defected from the ruling party and turned the election into a referendum on the president and the enormous power he wields over the island nation of 21 million.

Elections commissioner Mahinda Deshapriya said the election was peaceful, although some voters were prevented from casting ballots in the Tamil-dominated north, according to the Centre for Monitoring Election Violence.

Until just a few weeks ago, Mr Rajapaksa was widely expected easily to win his third term in office.

But that changed suddenly in November when Mr Sirisena split from him, and gathered the support of other defecting politicians and many of the country's ethnic minorities, making the election a fierce battle.

Mr Rajapaksa was still thought to be tough to beat because he controlled the state media, has immense financial resources and is still popular among the Sinhala majority, some of whom see him as a saviour for destroying Tamil Tiger rebels and ending a decades-long civil war in 2009.

But polling was notably strong yesterday in Tamil-dominated areas, where voting had been poor in previous elections.

Many Tamils have felt abandoned since the war's end, when Mr Rajapaksa largely ignored Tamil demands to heal the wounds of the fighting and years of ethnic divisions. They were thought to have voted heavily for Mr Sirisena.

Both candidates are ethnic Sinhalese, who make up about three-quarters of the country. Neither has done much to reach out to Tamils, who account for about 9% of the population, but Mr Rajapaksa is deeply unpopular in the Tamil community.

The wider world was watching the election in case violence should erupt after the results are announced, especially since Pope Francis is scheduled to arrive in the country on Tuesday.

While Mr Rajapaksa's campaign centred on is victory over the Tamils and his work rebuilding the country's infrastructure and economy, Mr Sirisena's focused on reining in the president's expanding powers.

He also accused Mr Rajapaksa of corruption, a charge the president denies.

The economy has grown quickly in recent years, fed by enormous construction projects, many built with Chinese investment money. But Sri Lanka still has a large underclass, many of whom are increasingly frustrated at being left out.

Mr Rajapaksa's power grew immensely after he defeated the Tigers.

Following his victory in the last election in 2010 he jailed his opponent and used his parliamentary majority to scrap a constitutional two-term limit for the president and give himself the power to appoint judges, senior bureaucrats, police officials and military chiefs. He also orchestrated the impeachment of the country's chief justice.

He also installed numerous relatives in top government positions. One brother is a Cabinet minister, another is the speaker of parliament and a third is the defence secretary.

His older son is a member of parliament and a nephew is a provincial chief minister.