In a revealing interview, US President Barack Obama has expressed his frustrations with some leaders in the Middle East, including the "condescension" of Israel's Benjamin Netanyahu.

Jeffrey Goldberg's six-hour sit-down with Obama was published in The Atlantic and offers some insights into the president's dealings with other world leaders.

Obama, who is reaching the end of his second term, described an incident in which Netanyahu began lecturing him about the dangers of the Middle East.

"Obama felt that Netanyahu was behaving in a condescending fashion, and was also avoiding the subject at hand: peace negotiations," Goldberg writes.

The interview goes on to recount Obama's side of the exchange.

“Bibi, you have to understand something,” he said. “I’m the African-American son of a single mother, and I live here, in this house. I live in the White House. I managed to get elected president of the United States.

"You think I don’t understand what you’re talking about, but I do.”

Nethanyahu is not alone in having incurred Obama's displeasure.

According to Goldberg, Obama sees Turkish President Recep Tayyip Erdogan as a "failure and an authoritarian," despite having been initially optimistic about what he had to offer as a leader.

The piece also touches on the Obama administration's intervention in Libya, which Obama describes as "a mess" and admits "it didn't work".

He criticised British Prime Minister David Cameron and former French President Nicolas Sarkozy, suggesting that the former had become distracted after the bombing campaign that helped to overthrow Muammar Gaddafi ended, and that the latter wanted to promote his control.

“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,” he said.

“At that point, you’ve got Europe and a number of Gulf countries who despise Gaddafi, or are concerned on a humanitarian basis, who are calling for action. But what has been a habit over the last several decades in these circumstances is people pushing us to act but then showing an unwillingness to put any skin in the game … free riders,” he added.

Cameron stopped paying attention soon after the military operation, he said, becoming "distracted by a range of other things".

During the bombing campaign, Obama said, Sarkozy wanted to "trumpet the flights he was taking in the air campaign, despite the fact that we had wiped out all the air defences and essentially set up the entire infrastructure" for the operation.

Cameron and Sarkozy were cheered on a visit to Benghazi, the hub of the Libyan rebellion, at the end of 2011 after Gaddafi had been deposed and then killed. But the country has remained in political chaos ever since, with control of the country currently divided between two rival governments.

The Islamic State (IS) group has also established territory around Sirte in the centre of the country, drawing several US air strikes and prompting speculation of a new international intervention.

In a statement to the BBC after the Atlantic interview had been published, the White House said that David Cameron had been as close a partner as Obama has had during his presidency.

"We deeply value the UK's contributions on our shared national security and foreign policy objectives which reflect our special and essential relationship," the statement said.

"With respect to Libya, the president has long said that all of us - including the United States - could have done more in the aftermath of the Libyan intervention."

In a statement, Cameron's office also defended the UK's role in Libya as "the right thing to do".

"We agree that there are still many difficult challenges in Libya but, as the PM has said many times before, coming to the aid of innocent civilians who were being tortured and killed by their leader was the right thing to do."

The UK had "sought to support the people of Libya" and was still "working hard to support the UN-led process to establish a stable and inclusive government," Downing Street said.