Gates told an audience in New York about Specialist Zachary Boyd, routed from sleep by enemy fire on his post in eastern Afghanistan.
"He immediately grabbed his rifle and rushed into a defensive position clad in his helmet, body armor, and pink boxer shorts that said 'I Love New York,"' Gates said Thursday night.
"Unfortunately, or fortunately, depending on your perspective, an AP photographer was there for a candid shot," Gates continued.
The photograph by David Guttenfelder ran on the front page of the New York Times.
Gates said Boyd later told his parents he might get fired. Gates assured his audience at the Intrepid museum, and Boyd, that his job is safe.
"Any soldier who goes into battle against the Taliban in pink boxers and flip-flops has a special kind of courage," Gates said, adding that Boyd may have hit on a new kind of psychological warfare. "I can only wonder about the impact on the Taliban. Just imagine seeing that - a guy in pink boxers and flip-flops has you in his crosshairs."