"I declare ... Prime Minister Mahinda Rajapakse as the winner of the presidential election," Elections Commissioner Dayananda Dissanayake told a news conference on Friday.
Thursday's poll was seen as a referendum on how to rescue the island's faltering peace process and tsunami-hit economy, but a boycott by Tamil Tiger rebels helped the hawkish Rajapakse by keeping away ethnic Tamil voters expected to back Wickremesinghe.
With all ballots counted, Rajapakse - a hardliner towards Tamil Tiger rebels - received 4.88 million votes, or 50.29% of the total 9.7m valid votes cast, AD de Silva, a member of the Election Commission said on Friday.
Opposition leader Wickremesinghe received 4.70m, or 48.38%. The remaining votes were cast for the other 11 candidates.
Election officials said that voting in Thursday's election was smooth in western and southern parts of the island and overall turnout was 75%.
But in the north and east - territory controlled by the Tiger rebels - grenade attacks, roadblocks and fear kept many Tamils from voting.
Others heeded a boycott called by pro-rebel groups that complained neither of the main candidates would help them win a homeland in northeastern Sri Lanka.
The Tamils, whose plight is at the heart of a civil war that has lasted more than two decades, make up just under 20% of Sri Lanka's 19 million people but were potential kingmakers in the tightly contested election.
Wickremesinghe plans to strike
a deal with Tamil rebels
The race pitted Rajapakse against dovish opposition leader Wickremesinghe, whose softer line on peace talks with the rebels won him wide support among Tamils, a largely Hindu minority.
The new president "will have to sort out the country's main ethnic problem", said one voter, D Maulana, 35, who sells auto parts in Colombo.
"As all of us know without that, nothing can go forward until it is over."
Rajapakse, who turns 60 on Friday, has pledged to review the stalled peace process and not share political power or tsunami aid with the Tigers.
He insists his stance can lead to peace - a tough stand that has won him wide support among Sri Lanka's Sinhalese majority.
"I am not a candidate for war ... but it has to be an honourable peace," he said after voting in southern Sri Lanka.
Wickremesinghe, 56, who signed a ceasefire with the rebels in 2002 when he was prime minister, voted in Colombo.
Tight security was in place at
He promises to strike a peace deal by granting Tamils a degree of autonomy. He also favours further liberalising the economy.
No polling stations were set up in Tiger strongholds because of security concerns, but the government set up special voting booths on the edge of separatist territory to accommodate the more than 200,000 voters who live behind rebel lines.
But officials said roadblocks and intimidation kept most from making it out of the territory to vote.
Turnout was less than 1% in and around the northern Tamil city of Jaffna - the lowest ever in any of the Indian Ocean country's 22 districts.
Scene of clashes
Grenade blasts forced European Union observers to pull out of the eastern city of Batticaloa, the scene of frequent clashes between the Tigers and breakaway rebel factions.
At least two people were killed in the attacks.
In the Batticaloa district, split between the separatists and government, turnout was 43%, down from around 70% in the last presidential vote - a drop officials attributed to the fact that few Tamils from rebel areas voted.
Perinban, a 57-year-old Tamil farmer from a rebel area near the eastern village of Vavunathivu, wanted to vote.
"I am not a candidate for war ... but it has to be an honourable peace"
But on his way to the polling station he saw a roadblock of burning tyres and palm fronds and said he knew exactly what it meant: "Burning tyres are a signal that we should not go beyond this."
The Tigers took up arms in 1983 over perceived discrimination against Tamils, most of whom are Hindu, by the predominantly Buddhist Sinhalese majority.
Nearly 65,000 people have been killed in the conflict.