Mr. Gates says he found it dismaying to hear Hillary Rodham Clinton talk about her opposition to the 2007 surge in Iraq in terms of domestic politics and the Iowa primary. But in another passage, he praises her as “smart, idealistic but pragmatic, tough minded, indefatigable, funny, a very valuable colleague, and a superb representative of the United States all over the world.”

Vice President Joseph R. Biden Jr. does not fare as well. Mr. Gates says Mr. Biden is “impossible not to like” though, in his opinion, Mr. Biden “has been wrong on nearly every major foreign policy and national security issue over the past four decades.”

Mr. Obama’s national security aides like Denis McDonough and Ben Rhodes are singled out for some of Mr. Gates’s most stinging criticism. He suggests that such advisers were often “out of their depth” in foreign policy and military matters, and blurred the chain of command by circumventing more senior officials. In this respect, this book echoes the journalist James Mann’s 2012 book “The Obamians,” which argued that the president leaned heavily on an inner circle of young aides who had been with him through his 2008 campaign, while keeping more experienced hands at a distance.

Image Clockwise from top left, Ehud Olmert, the former prime minister of Israel; King Abdullah of Saudi Arabia; Denis McDonough, the White House chief of staff; and Ben Rhodes, the deputy national security adviser for strategic communications. Credit... Clockwise from top left: Nicholas Kamm/Agence France-Presse — Getty Images; Pool photo by Brendan Smialowski; Charles Dharapak/Associated Press; Jim Bourg/Reuters

The Obama White House, Mr. Gates writes, was “by far the most centralized and controlling in national security of any I had seen since Richard Nixon and Henry Kissinger ruled the roost.” He adds that its “controlling nature” and “its determination to take credit for every good thing that happened while giving none to the people in the cabinet departments — in the trenches — who had actually done the work, offended Hillary Clinton as much as it did me.”

Mr. Gates points out continuities in national security policies between Mr. Bush’s second term and Mr. Obama’s first. And he notes other similarities between the two presidents: both “had the worst of both worlds on the Hill: they were neither particularly liked nor feared” and did little to reach out to individual members of Congress; nor did either “work much at establishing close personal relationships with other world leaders.” In short, both seemed “very aloof with respect to two constituencies important to their success in foreign affairs.”

Regarding the Bush administration, the most compelling parts of this book concern Iran and Mr. Gates’s worries about “the influence of the Israelis and the Saudis” on the White House, particularly the Israeli prime minister Ehud Olmert and King Abdullah of Saudi Arabia and “their shared desire to have problems like Iran ‘taken care of’ while Bush was still president.” Mr. Gates repeatedly warned of the dangers of “looking for another war” when America was already at war in Iraq and Afghanistan. At one point, he says, he was so worried that Mr. Bush might be persuaded by Vice President Dick Cheney and Mr. Olmert “to act or enable the Israelis to act” (that is, to take military action to prevent Iran from getting a nuclear weapon) that he made an intense private call to Mr. Bush in which he argued “we must not make our vital interests in the entire Middle East, the Persian Gulf and Southwest Asia hostage to another nation’s decisions — no matter how close an ally.”