* Sirisena expected to improve ties with India
* Rajapaksa miscalculated decline in popularity despite war triumph
* New coalition government may struggle to deliver economic reform (Adds rating agency and China comment)
By Shihar Aneez and John Chalmers
COLOMBO, Jan 9 (Reuters) - 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.
Opposition candidate Maithripala Sirisena, a one-time ally of Rajapaksa who defected in November and derailed what the president thought would be an easy win, took 51.3 percent of the votes polled in Thursday's election. Rajapaksa got 47.6 percent, according to the Election Department.
Celebratory firecrackers were set off in the capital, Colombo, after Rajapaksa conceded his defeat to Sirisena, who has vowed to root out corruption and bring constitutional reforms to weaken the power of the presidency.
Sri Lanka's stock market climbed to its highest in nearly four years.
"We expect a life without fear," said Fathima Farhana, a 27-year-old Muslim woman in Colombo. "I voted for him because he said he will create equal opportunities for all," she said of Sirisena, a soft-spoken 63-year-old from the rice-growing hinterlands of the Indian Ocean island state.
Like Rajapaksa, Sirisena is from the majority Sinhala Buddhist community, but he has reached out to ethnic minority Tamils and Muslims and has the support of several small parties.
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.
U.S. 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.
Indian Prime Minister Narendra Modi telephoned Sirisena to congratulate the new leader of "a close friend and neighbour".
Sri Lanka is just off India's southern coast and has historically had mixed ties with its much larger 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.
Chinese Foreign Ministry spokesman Hong Lei said Beijing believed the new government would maintain a friendly policy towards China and support investment projects already agreed.
Sirisena is expected to be sworn in at Colombo's Independence Square at 6:00 p.m. (1230 GMT).
The results showed Rajapaksa remained popular among Sinhala Buddhists, who account for about 70 percent of the country's 21 million people, but Sirisena earned his lead with the support of the ethnic Tamil-dominated former war zone in the north and Muslim-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 powerful positions. Although the economy had blossomed since the end of the war, voters complained of the high cost of living.
Rajapaksa had called this 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.
"The opposition's coalition parties have not agreed on a common approach to economic policy and, in our view, were mainly united by the desire to unseat Rajapaksa," Standard and Poor's Ratings Services said in a statement.
"Policy differences are likely to surface."
Sirisena 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 sea in Colombo, will be cancelled.
However, Sirisena's backers have said a casino licence given to Australian gambling tycoon James Packer's Crown Resorts Ltd will be withdrawn. (Additional reporting by Ranga Sirilal in Colombo and by Megha Rajagopalan in Beijing; Editing by Raju Gopalakrishnan and robert Birsel)