Barack Obama has sharply criticised David Cameron for the UK’s role in allowing Libya to become a “shit show” after the fall of the dictator Muammar Gaddafi, in an unprecedented attack on a British leader by a serving US President.

Mr Obama said that following a successful military intervention to aid rebels during the 2011 Arab Spring revolt, Libya was left to spiral out of control – due largely to the inaction of America’s European allies.

In a candid US magazine interview, Mr Obama said: “When I go back and I ask myself what went wrong… there’s room for criticism, because I had more faith in the Europeans, given Libya’s proximity, being invested in the follow-up.”

Singling out the British Prime Minister, he suggested that Mr Cameron had taken his eye off Libya after being “distracted by a range of other things”.

Mr Cameron and Nicolas Sarkozy, then the French President, pushed hard for the bombing raids on Colonel Gaddafi’s forces that led to his fall, but since 2011 Libya has sunk further into violence and civil war, and latterly has become a focal point for Isis in North Africa.

Mr Obama went on: “We actually executed this plan as well as I could have expected: We got a UN mandate, we built a coalition, it cost us $1bn – which, when it comes to military operations, is very cheap. We averted large-scale civilian casualties, we prevented what almost surely would have been a prolonged and bloody civil conflict. And despite all that, Libya is a mess.”

Referring to that mess in private, Mr Obama reportedly uses the more colourful term, “shit show”.

A Libyan fireman stands in front of an oil storage tank at an oil facility in northern Libya's Ras Lanouf region in February, after it was set ablaze following attacks launched by Isis jihadists (AP)

The comments will be a severe embarrassment to Mr Cameron, who has often been forced to defend British involvement in Libya on the grounds that Western intervention helped to avert a bloodbath. They will also place strain on the transatlantic alliance as coalition forces target Isis positions in Syria and Iraq.

Mr Cameron’s spokeswoman said he had frequently made clear that he still believed military action in Libya was “absolutely the right thing to do” and stressed that the Government had put support for the country on the agenda when the UK hosted a meeting of G8 leaders in 2013.

Libya marks five years since start of revolution

She said: “We would share the President’s assessment that there are real challenges in Libya. That’s why we are continuing to work hard with international partners to support a process in Libya that puts in place a government that can bring stability, and why we are talking about how we can support such a government in the future.”

Speaking at length to The Atlantic, Mr Obama revealed that the Prime Minister had risked damaging the countries’ “special relationship” by delaying an increase in defence spending to meet a Nato target of 2 per cent of GDP. Alluding to Mr Cameron’s foot-dragging, Mr Obama said: “Free riders aggravate me.”

Dave Brown on Barack Obama Show all 7 1 /7 Dave Brown on Barack Obama Dave Brown on Barack Obama 13 January 2016 Obama's executive actions on gun control laws Dave Brown on Barack Obama 10 December 2014 Senate Intelligence Committee report on torture is published Dave Brown on Barack Obama 6 November 2014 Republican gains in the mid-terms leave Obama looking like a lame duck Dave Brown on Barack Obama 19 September 2014 Obama’s strategy on Isis is criticized as confused Dave Brown on Barack Obama 23 August 2014 Obama steps up air strikes against Isis in Iraq Dave Brown on Barack Obama 13 August 2014 Obama authorises renewed military action in Iraq. Meanwhile tributes abound after the death of Robin Williams Dave Brown on Barack Obama 25 May 2013 Obama sets out new legal framework for use of drones

When the two came face to face at the G7 summit in June 2015, Mr Obama told Mr Cameron: “You have to pay your fair share.” The next month, Chancellor George Osborne’s summer Budget included a defence spending rise.

Mr Obama also said Mr Cameron’s failures had affected his decision not to enforce a “red line” over President Bashar al-Assad’s use of chemical weapons during the Syrian civil war. The President had planned a strike against Assad’s forces in August 2013, following a deadly sarin gas attack by the regime on civilians in a Damascus suburb. The strike was called off at the 11th hour. One “major factor” in the decision, the President said, “was the failure of Cameron to obtain the consent of his Parliament” for military action.

During his White House tenure, Mr Obama explained, he has tried to encourage other nations to act in international matters without always waiting for the US to take the lead.

“It was precisely to prevent the Europeans and the Arab states from holding our coats while we did all the fighting that we, by design, insisted” that they spearhead the Libyan intervention, he said, describing the strategy as “part of the anti-free rider campaign”.