LONDON - The British government feared a furious Libyan reaction if the convicted Lockerbie bomber wasn't set free, and expressed relief when it learned that he would be released on compassionate grounds, leaked U.S. diplomatic cables show.

Cables from the U.S. Embassy in Tripoli describe the run-up to the decision to free Abdel Baset Ali al-Megrahi, a Libyan agent whose freedom on Aug. 20, 2009, sparked jubilation in Libya but roiled relations between London and Washington.

Critics of the decision have alleged that British officials were motivated by commercial interests - including those of the energy company BP P.L.C. - when they moved to free Megrahi, the only man convicted in the 1988 attack on Pan Am Flight 103.

While officials here have always stressed that the 58-year-old Megrahi was released because he suffered from terminal prostate cancer, the cables show the British were keenly aware that they faced a damaging backlash if they didn't do as the Libyans wanted.

Britain was caught "between a rock and a hard place," an Oct. 24, 2008, U.S. cable warned. "The Libyans have told HMG [Her Majesty's Government] flat out that there will be 'enormous repercussions' for the UK-Libya bilateral relationship if Megrahi's early release is not handled properly."

Britain's ambassador to Tripoli, Vincent Fean, said a few months later that a refusal to release the convicted terrorist would have meant disaster for British interests in Libya.

"They could have cut us off at the knees, just like the Swiss," the cable quotes Fean as saying.

Fean seemed to be referring to the Swiss detention of Moammar Gadhafi's son and daughter-in-law in July 2008 for assaults on their servants in Geneva, Switzerland - arrests that sparked a collapse of relations between the two countries, with Libya cutting off oil supplies, and that forced the Swiss into an abject apology.

British officials have acknowledged that commercial interests - as well as the desire to deepen antiterrorism cooperation - played a role in the U.K.-Libyan prisoner-transfer agreement that led to Megrahi's release.

But they have always stressed that the decision to release Megrahi on compassionate grounds was made independent of that deal and that, in any case, officials in the Scottish capital of Edinburgh had the final say on whether to set him free.

Scotland has insisted that its decision was made on humanitarian grounds alone, although one cable does suggest that Libya tried to lean on the Scottish government to do its bidding.

Scottish First Minister Alex Salmond is quoted in the cables as telling a U.S. official that the Libyans had offered the Scottish government "a parade of treats" in return for Megrahi's release. His office on Wednesday said he never said that.

Megrahi is still believed to be alive in Libya, even though doctors estimated he had only a few months to live when he was freed.