The secretary of defense knew it was time to go, even though his war, still painfully un-won, was destined to drag on with no certainty of a satisfying outcome.

And near the end, there was a public moment when emotion overtook this SecDef who was famous among his insiders for being cool and controlled in tough times.

It happened in the White House East Room when the president presented his secretary of defense with the Medal of Freedom, the highest honor a commander in chief can give a civilian. The secretary, overwhelmed by emotion, fought one last battle before losing to the tears that filled his eyes and rolled down his cheeks. “I cannot find the words to express what lies in my heart,” he said, “and I guess I better respond on another occasion.”

That was February 1968 and it was not until 1995 when former Secretary of Defense Robert McNamara found the words that were really in his heart that day and every day since. Long after President Lyndon Johnson was dead, McNamara wrote the words Johnson would never have wanted to read: “We were wrong, terribly wrong.”

Fast forward to now. Another long-serving defense secretary, Robert Gates, has just produced a memoir that, while it couldn’t compare to the shock of McNamara’s tragic admission, has nevertheless stunned the world within Washington’s Beltway.

Gates, who spent five years prosecuting troubled wars in Afghanistan and Iraq for Presidents George W. Bush and Barack Obama, rushed to deliver his book (titled “Duty”) so it would be read before the 2016 presidential campaign.

Gates’ book castigates Obama and his White House. He is right when he complains about the tight, controlling ways of Obama’s White House — but that’s just standard Washington payback.

It’s the heart of Gates’ book that stunned even Gates’ Republican allies — for he harshly criticizes the motives of his former boss and current president. Here Gates seems to have co-authored his memoir with his polar-opposite twin. Gates seems of two minds in his memoir.

Consider Gates’ recounting of Obama’s decision, opposed by many Democrats, to send 30,000 more troops to Afghanistan.

Gates wrote: “The president doesn’t trust his commander ... doesn’t believe in his own strategy and doesn’t consider the war to be his. For him, it’s all about getting out.”

But wait — Gates also wrote, concerning Obama’s crucial Afghan war decisions: “I believe Obama was right in each of these decisions.” And when he wasn’t blasting Obama, Gates was praising him. He said Obama is “very thoughtful and analytical, but he is also quite decisive. ... I think we have a similar approach to dealing with national security issues.”

Finally, Gates wrote: “I never doubted Obama’s support for the troops, only his support for their mission.”

But the Afghanistan war is America’s longest war ever. Shouldn’t any thinking leader have doubts, given the history of strategies that finished short of expectations? Gates grants himself that, but apparently not his president.

On Gates’ last day, Obama had presented him with the Medal of Freedom, in a ceremony that was filled with words of mutual admiration. The framed citation hangs proudly on Gates wall today, in the study where Gates wrote the book so criticizing the president who had praised, honored, respected and trusted him.

There is a human condition at the core of older folks whose job is to send younger folks into wars that may end without being won. Gates kept count of every military casualty in Afghanistan and Iraq while he was secretary. He wrote personalized letters to families of each service member who was killed.

In his last visit to U.S. troops in Afghanistan, in December 2010, Gates, who, like McNamara, was also known for being cool and controlled, also emotionally choked up.

“I feel a personal responsibility for each and every one of you,” he said in a voice choked with tears. “... I just want to thank you and tell you how much I love you.”

Love is not your standard GI-issued message from the SecDef. But it was all Bob Gates had left as he stood there that day.

And sadly now, what this excellent and patriotic defense secretary had left for the rest of us is mainly just the sort of petty Washington squabbles and payback Bob Gates always detested hearing from others.