President Obama surprised Robert Gates on Thursday, awarding the retiring defense secretary the Presidential Medal of Freedom for his four decades of public service, including the last four and a half years at the Pentagon.

The medal is the highest honor the president can give a civilian, and came as a shock to Gates, whose voice wavered after being told of the honor.

Saying credited the president and his colleagues with keeping the honor a secret, and joked to the president, "We should all know by know you're getting pretty good at this covert ops stuff."

At a ceremony marking Gates' retirement, Obama called him a humble American patriot, a man of common sense and decency, and one of the nation's finest public servants.

According to the White House, the citation reads: "Our nation's 22nd secretary of defense, Robert M. Gates has selflessly dedicated his life to ensuring the security of the American people. He has served eight presidents, of both parties, with unwavering patriotism. As a champion of our men and women in uniform and their families, he has led the Department of Defense with courage and competence during our nation's wars in Iraq and Afghanistan, and ensured our Armed Forces are better prepared for the conflicts of today and tomorrow. The United States honors Robert M. Gates for his extraordinary leadership and for a lifetime of service and devotion to our nation.”

Gates became defense secretary in December 2006 under Republican President George W. Bush. He is being replaced by outgoing CIA Director Leon Panetta, whose first day begins Friday.

Gates was having a farewell lunch and returning to his home in Washington state with a customary military escort.