All too often during my 4½ years as secretary of defense, when I found myself sitting yet again at that witness table at yet another congressional hearing, I was tempted to stand up, slam the briefing book shut and quit on the spot. The exit lines were on the tip of my tongue: I may be the secretary of defense, but I am also an American citizen, and there is no son of a bitch in the world who can talk to me like that. I quit. Find somebody else. It was, I am confident, a fantasy widely shared throughout the executive branch.

Much of my frustration came from the exceptional offense I took at the consistently adversarial, even inquisition-like treatment of executive-branch officials by too many members of Congress across the political spectrum—creating a kangaroo-court environment in hearings, especially when television cameras were present. But my frustration also came from the excruciating difficulty of serving as a wartime defense secretary in today's Washington. Throughout my tenure at the Pentagon, under both President George W. Bush and President Barack Obama, I was, in personal terms, treated better by the White House, Congress and the press for longer than almost anyone I could remember in a senior U.S. government job. So why did I feel I was constantly at war with everybody? Why was I so often so angry? Why did I so dislike being back in government and in Washington?

It was because, despite everyone being "nice" to me, getting anything consequential done was so damnably difficult—even in the midst of two wars. I did not just have to wage war in Afghanistan and Iraq and against al Qaeda; I also had to battle the bureaucratic inertia of the Pentagon, surmount internal conflicts within both administrations, avoid the partisan abyss in Congress, evade the single-minded parochial self-interest of so many members of Congress and resist the magnetic pull exercised by the White House, especially in the Obama administration, to bring everything under its control and micromanagement. Over time, the broad dysfunction of today's Washington wore me down, especially as I tried to maintain a public posture of nonpartisan calm, reason and conciliation.

I was brought in to help salvage the wars in Iraq and Afghanistan—both going badly when I replaced Donald Rumsfeld in December 2006. When I was sworn in, my goals for both wars were relatively modest, but they seemed nearly unattainable. In Iraq, I hoped we could stabilize the country so that when U.S. forces departed, the war wouldn't be viewed as a strategic defeat for the U.S. or a failure with global consequences; in Afghanistan, I sought an Afghan government and army strong enough to prevent the Taliban from returning to power and al Qaeda from returning to use the country again as a launch pad for terror. Fortunately, I believe my minimalist goals were achieved in Iraq and remain within reach in Afghanistan.

President Bush always detested the notion, but our later challenges in Afghanistan—especially the return of the Taliban in force by the time I reported for duty—were, I believe, significantly compounded by the invasion of Iraq. Resources and senior-level attention were diverted from Afghanistan. U.S. goals in Afghanistan—a properly sized, competent Afghan national army and police, a working democracy with at least a minimally effective and less corrupt central government—were embarrassingly ambitious and historically naive compared with the meager human and financial resources committed to the task, at least before 2009.