He had visited the convicted Megrahi in Barlinnie prison in 2002 having been credited with helping to break the diplomatic deadlock between Libya, the US and Britain that allowed Megrahi's trial to go ahead.
The former South African president had helped to persuade Colonel Muammar Gadaffi, the Libyan president, to hand over the two men accused of planting the bomb, convincing him that they would receive a fair trial.
Mandela was said, however, to have been disappointed when it was agreed that a Scottish court sitting in the Netherlands was to try the men. He had favoured an international panel of judges.
The South African arrived at the Glasgow jail heavily guarded by a posse of police officers, diplomats and South African secret servicemen.
Mandela, who spent 27 years in Robben Island prison for his opposition to South Africa's apartheid regime, backed calls for a fresh appeal into Megrahi's conviction and an independent inquiry into the December 1988 bombing of the Pan Am jet, which claimed the lives of 270.
And he caused outraged when he pleaded to the Government for the Libyan to be transferred from Barlinnie to serve his minimum 20-year sentence in a Muslim country, such as Tunisia or Egypt, where he would not feel so isolated. He described Megrahi's solitary confinement as nothing short of "psychological persecution".
He said: "I profited a great deal by serving my sentence with other people. Our minds were occupied every day by something positive. For that reason it's difficult for me to believe that I was in jail for 27 years or so."
But Foreign Secretary Jack Straw said that the move was out of the question.
Mr Straw quoted a report by independent UN monitors who had visited Megrahi at Barlinnie and concluded that his conditions were "good, meeting all known national and international standards".
Mr Straw added that Megrahi's guards had shown "commendable awareness of, and respect for, cultural and religious differences".
Four years ago, when the Scottish Justice Secretary Kenny MacAskill was under intense pressure following the release of the Libyan on compassionate grounds, it emerged the Scottish Government received a letter saying the former South African president expressed his support for the move.
In the letter to the Scottish government, Professor Jake Gerwel, the chairperson the Mandela Foundation, said: "Mandela sincerely appreciates the decision to release Megrahi on compassionate grounds."
It added: "Mandela played a central role in facilitating the handover of Megrahi and his fellow accused to the United Nations in order for them to stand trial under Scottish law in the Netherlands.
"His interest and involvement continued after the trial after visiting Mr Megrahi in prison.
"The decision to release him now, and allow him to return to Libya, is one which is therefore in line with his wishes."
Scottish First Minister Alex Salmond said there was "huge support" internationally for the decision to free Megrahi - who had terminal prostate cancer - to allow him to return home to Libya to die.
Mr Salmond said: "We have seen that Nelson Mandela has come out firmly in support, not just as the towering figure of humanitarian concern across the world in the last generation, but of course somebody who brokered the agreement that led to the Lockerbie trial in the first place."
He added: "Many people believe that you will achieve more in this world through acts of mercy than you will through acts of retribution."