Sri Lankan President Mahinda Rajapaksa lost his bid for a third term on Friday, ending a decade of rule that critics say had become increasingly authoritarian and marred by nepotism and corruption.
As results rolled in overnight from Thursday's election, it became clear that Rajapaksa had been beaten by opposition candidate Mithripala Sirisena, a one-time ally who defected overnight in November and derailed what the president thought would be an easy win.
Celebratory firecrackers could be heard exploding in the capital, Colombo, after Rajapaksa's office said he had accepted the victory of Sirisena, who has vowed to root out corruption and bring constitutional reforms to weaken the power of the presidency.
Sirisena, a soft-spoken 63-year-old from the rice-growing hinterlands of this Indian Ocean island state, is expected to be sworn in at Colombo's Independence Square at 6:00 pm. local time (12.30 pm BST).
His allies say he will rebalance the country's foreign policy, which tilted heavily towards China in recent years as Rajapaksa fell out with the West over human rights and allegations of war crimes committed at the end of a drawn-out conflict with Tamil separatists in 2009.
US Secretary of State John Kerry was quick to welcome the successful election and commended Rajapaksa for accepting the verdict of the nation's 15 million voters.
"I look forward to working with President-elect Mithripala Sirisena as his new government works to implement its campaign platform of a Sri Lanka that is peaceful, inclusive, democratic, and prosperous," he said in a statement.
Indian Prime Minister Narendra Modi called Sirisena to congratulate the new leader of "a close friend and neighbour".
Rajapaksa had cold-shouldered New Delhi in recent years, but Sirisena told an Indian newspaper this week that "we will revert to the old, non-aligned policy".
"India is our first, main concern. But we are not against Chinese investment either. We will maintain good relations with China too," he told the Hindustan Times.
The Department of Elections said that of 7.6 million votes counted so far, Sirisena had taken 52.05 per cent and Rajapaksa was trailing on 46.7 per cent.
The results showed Rajapaksa remained popular among Sinhala Buddhists, who account for around 70 percent of the country's 21 million people, but Sirisena took his lead from the ethnic Tamil-dominated former war zone in the north and Muslims-dominated areas.
Rajapaksa won handsomely in the last election in 2010, surfing a wave of popularity months after the defeat of the Tamil Tiger rebels.
But critics say he had become increasingly authoritarian, with several members of his family holding key positions of power, and although the economy had blossomed since the end of the war, voters complained of the high cost of living.
Rajapaksa had called the latest election two years early, confident that the usually fractured opposition would fail to come up with a credible candidate. But he did not anticipate the emergence of Sirisena, who shared a traditional Sri Lankan dinner with him one evening and turned on him the next day.
Sirisena will lead a motley coalition of ethnic, religious, Marxist and centre-right parties, which analysts say could hamper economic reform and encourage populist policies.
He has pledged to abolish the executive presidency that gave Rajapaksa unprecedented power and hold a fresh parliamentary election within 100 days.
He has also promised a crackdown on corruption, which would include investigations into big infrastructure projects such as a $1.5 billion deal with China Communications Construction Co Ltd to build a port city.
It is not clear if the port, to be built on land reclaimed from the ocean in Colombo, will be cancelled. However, his backers have said a casino licence given to Australian gambling tycoon James Packer's Crown Resorts Ltd, will be withdrawn.