Mr Gates claims that, by early 2010, the president was no longer committed to his own plan for Afghanistan and “did not consider the war to be his”.
The former Pentagon chief alleges that, on matters of national security, the Obama administration is the most “controlling” since Richard Nixon was in the White House.
Washington has been left reeling by the stark allegations from Mr Gates, a former CIA director who is 70 and has worked for eight US presidents. He served more than four years as defence secretary, the last years of George W Bush’s administration and the first years of Mr Obama’s.
It is very unusual for such a high-level official to publicly attack his former boss – rarer yet when the boss is still president.
His book – Duty: Memoirs of a Secretary at War – is released on 14 January in the US but excerpts were made public for press reviews in New York and Washington.
Mr Gates, a self-professed Republican, writes that he loathed his job but kept calm and was known for being a team player.
Soon after Democrat Mr Obama was elected, Mr Gates already felt there was a “suspicion and distrust of senior military officers” from the top down.
Matters came to a head in March 2011 in a meeting in the White House to discuss pulling out of Afghanistan.
The president all but accused his commander, General David Petraeus, of leaking stories to the press without his authorisation.
Mr Gates wrote: “As I sat there, I thought: the president doesn’t trust his commander, can’t stand [Afghan president Hamid] Karzai, doesn’t believe in his own strategy and doesn’t consider the war to be his. For him, it’s all about getting out.”
Another undated conversation between Mr Obama and then US secretary of state Hillary Clinton on the Iraq troop surge left Mr Gates rattled.
He wrote: “Hillary told the president that her opposition to the surge in Iraq had been political because she was facing him in the Iowa primary [in 2008].
“The president conceded vaguely that opposition to the Iraq surge had been political.
“To hear the two of them making these admissions, and in front of me, was as surprising as it was dismaying.”
In praise of Mr Obama, Mr Gates said the president’s decision to order Navy Seals to raid a house in Pakistan believed to be the hiding place of Osama bin Laden was “one of the most courageous decisions I had ever witnessed in the White House”.
Gates’s memoir could have an impact on the 2016 presidential race, thanks to his comments on both vice-president Joe Biden and Mrs Clinton.
Both are being tipped as potential Democrat candidates.
Of Mrs Clinton he wrote: “I found her smart, idealistic, but pragmatic, tough-minded, indefatigable, funny, a very valuable colleague, and a superb representative of the United States all over the world.”
But of Mr Biden Mr Gates wrote that, while he is a “man of integrity”, he has “been wrong on nearly every major foreign policy and national security issue over the past four decades”.
Mr Gates’s conclusion about the Obama White House is that it is obsessed with surveillance and that it is determined to control “every aspect of national security policy and even operations”.
He wrote that under Mr Obama the White House is “by far the most centralised and controlling in national security of any I had seen since Richard Nixon and Henry Kissinger ruled the roost”.
Caitlin Hayden of the National Security Council said Mr Obama “deeply appreciates” Mr Gates’ “lifetime of service to our country”.
She added: “As has always been the case, the president welcomes differences of view among his national security team, which broaden his options and enhance our policies.”