"This is a victory for the people," Rajapakse said. "I thank those who voted for me and those who did not. I will work for all of them."
His main challenger, former army chief Sarath Fonseka, received 40.1 percent of the vote, but he vowed to challenge the result in court.
In a day of high drama that followed a bitter and vitriolic contest between the former allies, Fonseka was surrounded by heavily armed soldiers in a luxury hotel in central Colombo where he checked in on Tuesday night.
The 59-year-old claimed he was unable to leave because he would be arrested or assassinated, but he slipped out unimpeded late Wednesday, heading for a safe house in the Sri Lankan capital.
"The victory has been taken away from us by election-rigging and the violation of electoral laws," he told reporters soon after the verdict was announced.
"We did not get the result because of the wrongs done by them."The contest had been a straight race between the two men who engineered the decisive victory over the rebel Liberation Tigers of Tamil Eelam (LTTE), who fought for 37 years for a Tamil homeland.
But from close allies on the battlefield they turned into irreconcilable enemies after Fonseka, a political novice, decided to challenge his former boss at the ballot box on an anti-corruption platform.
The rancorous nature of the election campaign and the tit-for-tat accusations of foul play running up to the vote had suggested a contested result was likely.
Independent election monitors have criticised the abuse of state resources by the government for campaigning, as well as violence, on election day particularly in the north. They stopped short of repudiating the vote, however. Four people were killed and more than 1,000 cases of election-related violence were reported to police in the lead-up to Tuesday's contest. Another two people were reported dead in attacks on Wednesday.
Rajapakse, 64, is a nationalist who ordered the offensive against the Tamil Tigers that has since been dogged by war crimes allegations.
The UN says 7,000 civilians were killed during the final stages of the fighting amid allegations of extra-judicial killings. A total of 80,000-100,000 people died during the near-four-decade conflict, also according to UN figures.
For Fonseka and the assorted coalition of opposition parties that backed him, their next step will be to file a petition at the Supreme Court challenging the verdict.
But he suggested he might have to flee abroad because the government had stripped him of his security, which he said was a deliberate ploy to leave him vulnerable to assassination.
"They are behaving like murderers," he said at the press conference in the hotel, in which tourists, businesspeople and a wedding party mingled all day seemingly oblivious to the show of force outside.
The government said the soldiers were to guard against any trouble from army deserters who they believed were working for the opposition. Fonseka denied this and complained of intimidation.
Despite the threat of protests, the defeated father-of-two, who holds a US Green Card, made no call to his supporters to take to the streets.
Sri Lanka faces an enormous task in rebuilding its war-ravaged economy and is under stiff international pressure to secure a lasting political solution that addresses the grievances of its large Tamil minority.
Rajapakse and Fonseka, who belong to the Sinhalese majority, had both courted Tamil voters during the campaign with pledges of greater political inclusion and investment in the devastated northeast.
India, which has a large Tamil population, congratulated Rajapakse and voiced hope that he would help heal the rift between the Sinhalese and Tamil communities.
Rajapakse also signalled he was ready to mend faces with Western countries that were critical of the conduct of the war. Britain and the US had held back aid and a trade agreement with the EU was thrown into doubt because of the conflict.
"Most of our misunderstandings were due to the fighting. It is over now. I am on my second (and final) term and we can work together to address any outstanding issues," he said from his residence.