Mistakes made on the battlefield against an "enemy with no conscience and no remorse" will be magnified and transmitted globally in this Internet age, Gates warned the 977 members of the 48th academy class on a brisk, windy day beneath snowcapped Pikes Peak.
"We live in an age when friends and enemies alike will seek out and focus on any and all mistakes made under great stress," he declared. "When you are called to lead, when you are called to stand in defense of your country in faraway lands, you must hold your values and your honor close to your heart."
Gates said leaders must do what is right, even when it will bring bad publicity or sacrifice personal friendships.
"Don't kid yourselves: More often than not, doing this means traveling a lonely and difficult road," he said.
There have been several highly publicized incidents of U.S. forces mistreating or killing insurgents or civilians in Afghanistan and Iraq, including torture and humiliation of prisoners at Iraq's Abu Ghraib prison. Several U.S. Marines are accused of killing 24 civilians in Haditha, Iraq. A recent survey found that 39 percent of Marines said torture should be allowed to gather information from an insurgent.
Against that backdrop, Gates commended Congress and the news media as "the two pillars of our freedom under the Constitution."
He made similar remarks last week at the U.S. Naval Academy's commencement, when he told new naval officers they have the responsibility to inform people under their command that the military "must be nonpolitical" and to truthfully report to Congress, "especially when it involves admitting mistakes or problems."
About 23,000 people attended the graduation Wednesday, Air Force spokesman Meade Warthen said.
Gates was flying to Hawaii for meetings Thursday at U.S Pacific Command headquarters. On Friday he is scheduled to arrive in Singapore to attend an international conference on Asian security and meet separately with his counterparts from South Korea and other allied nations.