Former president Mahinda Rajapaksa's attempt to stage a comeback in Sri Lanka's general election has ended in defeat as results on Tuesday, August 18, showed the alliance that toppled him making decisive gains.

The ruling United National Party (UNP) was likely to fall just short of an outright majority but Prime Minister Ranil Wickremesinghe should still command enough support to form a stable government.

"I invite all of you to join hands," Wickremesinghe, 66, said in a statement as the count neared completion. "Let us together build a civilised society, build a consensual government and create a new country."

The outcome is a triumph for President Maithripala Sirisena, who beat his former ally Rajapaksa in a presidential vote in January and called early parliamentary polls to secure a stronger mandate for reforms.

Defeat for Rajapaksa will keep Sri Lanka on a non-aligned foreign policy course and loosen its ties with China, which during his rule pumped billions of dollars into turning the Indian Ocean island into a maritime outpost.

Wickremesinghe's UNP won 93 of the 196 seats up for grabs in multi-member constituencies. The alliance led by Rajapaksa's Sri Lanka Freedom Party (SLFP) took 83 seats after suffering losses. Final representation in the 225-seat chamber will be decided when 29 national seats are allocated by proportional representation.

UNP sources and political analysts said the lead was likely to widen, with the party on track to win 105-107 seats, just shy of a 113-seat majority.

Failed Comeback

Nationalist strongman Rajapaksa set his sights on becoming premier of an SLFP-led government but Sirisena, who succeeded him as party leader in January, has ruled that out and purged Rajapaksa loyalists from senior posts.

A group of Sirisena followers is expected to cross the floor to join a broad-based national unity government led by Wickremesinghe, who was likely to be confirmed in his post on Tuesday.

"The UNP will not have an overall majority - it will have to look for coalition partners from those who support Sirisena," said Paikiasothy Saravanamuttu, head of the Centre for Policy Alternatives.

With outside support, the centre-right alliance could hope to muster the two-thirds majority required to pass proposed constitutional reforms that would make government more accountable and simplify Sri Lanka's complex election laws.

The power struggle between the past and present presidents overshadowed the election in a country with a history of political feuding that has often spilled over into violence and even the assassination of its leaders.

A broad backlash against Rajapaksa's attempt to win an unprecedented third term led support to coalesce around his former health minister Sirisena, a humble figure with none of the muscular bravado of his predecessor.

Yet he could now be confronted with a judicial reckoning, along with two brothers who held high office, for alleged corruption and abuse of power during his decade in power. They have denied any wrongdoing.