For a man who considered himself "the ultimate insider" in Washington, Robert Gates made no secret of his desire to become an outsider.
Long before the 2008 election, Gates was asked whether he would consider serving as secretary of defense beyond the end of President George W. Bush's second term.
"The circumstances under which I would do that are inconceivable to me," Gates replied in an April 2008 Pentagon news briefing.
Gates even had a "countdown clock" that ticked down the days until the end of the Bush administration, when he could retire. But within weeks of President Obama's election, the clock became obsolete.
"I've thrown away the clock because it was absolutely useless," Gates said in December 2008.
Getting rid of things and people who didn't perform as planned became a hallmark of Gates' time in the Department of Defense.
Shortly after replacing Donald Rumsfeld in the Pentagon's E-Ring office suite, Gates was confronted with a scandal at Walter Reed Army Medical Center, the military hospital in Washington in which wounded troops from Iraq and Afghanistan are treated.
When a Washington Post investigation unearthed months of substandard care at Walter Reed, the man in charge of the hospital was fired, and the secretary of the Army resigned.
"I am disappointed that some in the Army have not adequately appreciated the seriousness of the situation," Gates said when announcing Secretary Francis Harvey's resignation. "Some have shown too much defensiveness and have not shown enough focus on digging into and addressing the problems."
Harvey wouldn't be the last top Defense official to find himself out of work under Gates.
In June 2007, just months after Harvey left, Gates announced that he would not recommend Gen. Peter Pace for a second term as chairman of the Joint Chiefs of Staff, the first not to get a second term since the Kennedy administration.
"There was the very real prospect the process would be quite contentious," Gates said of Pace's Senate confirmation hearings. "I have decided that at this moment in our history, the nation, our men and women in uniform, and Gen. Pace himself would not be well-served by a divisive ordeal in selecting the next chairman of the Joint Chiefs of Staff."
Pink slips flew again a year later in the upper echelons of the Air Force after two incidents displayed problems involving the handling of nuclear weapons and equipment. Gates said the incidents, including one in which a B-52 bomber flew across the country without anyone on board knowing that six of the missiles on board were nuclear-tipped, showed that the "focus of the Air Force leadership has drifted."
The changes Gates made apparently didn't leave a sense of bitterness among those still in leadership positions at the Pentagon.
"He was quite tough and fired a lot of people," said Tom Ricks, a Pulitzer Prize-winning reporter who has covered the Pentagon for years. But "look at how the place calmed down, compared to when (Donald) Rumsfeld was there. The Iraq war was run better; the generals felt like they had adult leadership."
Michael O'Hanlon, a senior fellow at the Brookings Institution, agrees: "He maintained a spirit and tone of competence and professionalism and collegiality and yet also accountability."
During the early months of his tenure, Gates focused on implementing the "troop surge" in Iraq, a strategy change that was under consideration before he became secretary. It called for increasing the number of troops in Iraq and focusing their efforts in Baghdad. The goal was to have Iraqi troops take the lead in military matters and allow political progress to proceed by isolating extremists.
Although many on both sides of the political spectrum opposed the idea of 20,000 more American troops in Iraq, by 2008, violence declined, and Gates began overseeing the withdrawal of U.S. troops from the country, an endeavor that continues.
After working his way up from an entry-level job at the Central Intelligence Agency to the director's chair, Gates retired and laid out his career in the intelligence community in his autobiography "From the Shadows: The Ultimate Insider's Story of Five Presidents and How They Won the Cold War."
Now he was serving a sixth president and overseeing two hot wars. But he wasn't looking forward to staying on for a seventh. He frequently joked about getting away from the capital.
"It's a pleasure to be back here at West Point, although as I often say, 'It's always a pleasure to be away from Washington, D.C.,' " Gates told cadets at the U.S. Military Academy.
But after Obama won the 2008 election, he reached out to Gates in a secret meeting at a fire station at Reagan National Airport in Washington. Gates said he was impressed by what Obama said and agreed to stay on. Gates, a Republican, became the first secretary of defense to serve in both Democratic and Republican administrations.
His first major initiative was to oversee changes in the war in Afghanistan, even as the troop surge in Iraq was still winding down. Less than two weeks after his inauguration, Obama talked with Gates about the military's plans to send thousands more U.S. troops to Afghanistan.
Gates said a few days later that the goal of those troops was "to bring greater security in places like Helmand (province) by being a permanent presence there -- by being a long-term presence rather than flying out by helicopter for a day's operations or a couple of days' operations and then flying back to their base."
The increase in troops has led to a spike in U.S. troop deaths in the almost-10-year-old war. But by June, the Obama administration will begin withdrawing troops from the country, putting security issues more into the hands of Afghan security forces.
The U.S. commander in Afghanistan at the time of the surge was Gen. David D. McKiernan, who had been asking for more troops. But even before all those troops arrived, McKiernan was out.
"We have not been able to fully resource our military effort in Afghanistan in recent years, " Gates said when he announced in May 2009 that McKiernan would be replaced. "I believe, resources or no, that our mission there requires new thinking and new approaches from our military leaders. "
McKiernan was replaced by Gen. Stanley McChrystal, the former chief of special operations, who had already served in Afghanistan.
But changes in personnel were not Gates' only priority that winter. His fiscal year 2010 budget request, his first under Obama, showed that he could be just as cold in slashing the budget as he was in terminating careers.
In the request, Gates cut spending on F-22 fighter jets, the Army's Future Combat System and the Navy's next generation of destroyers. He ended plans to build a new fleet of presidential helicopters and ended purchases of C-17 cargo jets. The cuts, while criticized by Congress, lead to hundreds of billions of dollars in savings for the department, according to the Pentagon.
A year later, Gates was still fighting to trim the defense budget while the country dealt with two wars and a new financial crisis.
"Given America's difficult economic circumstances and perilous fiscal condition, military spending on things large and small can and should expect closer, harsher scrutiny," he said in Abilene, Kansas. "The gusher has been turned off and will stay off for a good period of time."
Critics say Gates' budget priorities are misguided. James Carafano, who directs the Heritage Foundation's Douglas and Sarah Allison Center for Foreign Policy Studies, says Gates has mortgaged the future of the country's defense.
"Gates took a military that's stretched and gutted its future. The U.S. will pay the price for that, and it will be his legacy far more than stage-managing Iraq and Afghanistan."
As he prepares to pack up his office, including the pictures of his home in Washington state to which he has so longed to return, Gates has found himself overseeing U.S. involvement in a third conflict in Libya.
Just in February, Gates was back at West Point, and he told the cadets, "In my opinion, any future defense secretary who advises the president to again send a big American land army into Asia or into the Middle East or Africa should 'have his head examined,' as Gen. (Douglas) MacArthur so delicately put it."
But just weeks later, the Navy and Air Force were heavily involved in enforcing a United Nations-sanctioned no-fly zone over Libya. Although seeming to follow Gates' advice, Obama issued a strict "no-boots-on-the-ground" rule for U.S. troops there. And American involvement in Libya has been scaled back and turned over to international partners.
Gates is still cutting programs and making some in Congress angry.
In April, the department announced that it was ending the program to develop an alternative engine for the new F-35 Joint Strike Fighter. Supporters said the program created 1,000 jobs, but Gates has called the program -- estimated to cost $1.8 billion to $2.9 billion -- unjustified and excessive.
Such cuts are one reason why Carafano says history will not look kindly on Gates' tenure as secretary of defense.
But both Ricks and O'Hanlon rate Gates as among the best.
"He helped turn around Iraq; he did a good job with Afghanistan; he brought stability at a turbulent time," O'Hanlon said.
As for Gates himself, when asked about his legacy during what will likely be his last visit to the troops in Iraq, he said that although his agenda was no longer just Iraq, that's what he would judged on.
"And I'll let people judge for themselves."