COLOMBO, Sri Lanka — Sri Lankan President Mahinda Rajapaksa has conceded defeat in his bid for a third term in office, his spokesman said Friday.

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, 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 Center for Monitoring Election Violence.

Until just a few weeks ago, Rajapaksa was widely expected to easily win his third term in office. But that changed suddenly in November when Sirisena split from him, and gathered the support of other defecting lawmakers and many of the country's ethnic minorities, making the election a fierce political battle.

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 savior for destroying Tamil Tiger rebels and ending a decades-long civil war in 2009.

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

The results highlighted the ethnic polarization in the country, with Tamils and Muslims, the second-largest ethnic minority, both voting against Rajapaksa.

Rajapaksa was accused of backing ultranationalist Buddhist groups and turning a blind eye on anti-Muslim violence last June.

Many Tamils have felt abandoned since the war's end, when 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 Sirisena.

Both Sirisena and Rajapaksa 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 percent of the population, but Rajapaksa is deeply unpopular in the Tamil community.

The wider world was watching to see if the election was carried out fairly, especially since Pope Francis is scheduled to arrive in the country on Tuesday.

While Rajapaksa's campaign centered around his victory over the Tamils and his work rebuilding the country's infrastructure and economy, Sirisena's focused on reining in the president's expanding powers. He also accused 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.

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, top 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 defense secretary. His older son is a member of Parliament and a nephew is a provincial chief minister.