“His deployment probably gave him a wake up,” said David W. Barno, a retired Army lieutenant general and former top commander in Afghanistan . “It is a unique place in society where you have a white male who works for someone African-American 10 years older than you from a very different cultural background. He talks about the leveling experience of being in the military.”

It was a theme that would stick, even after Mr. Buttigieg was honorably discharged in 2017.

While in Afghanistan, Mr. Buttigieg spent many days gingerly making his way through Kabul on convoy security in a heavily armed Land Cruiser. “I thought I was sent to Kabul for my experience in bureaucratic politics,” he said, “but because I was rifle qualified, it was my ability to drive a vehicle with two long guns” that got him that assignment, he said. “At the end of the day my usefulness was as a driver more than an elected officer.”

Thomas Gary, a senior petty officer at Naval Station Great Lakes near Chicago, who worked with Mr. Buttigieg before he became mayor, said he kept his politics low key. “I didn’t even know he was a Democrat until he won his primary for mayor,” he said. “That wasn’t something he advertised. I do remember when he was sworn in, I wanted to make sure we from the unit showed a little love for this accomplishment.”

Mr. Buttigieg spent his down time in Kabul tooling around the base’s cigar club, playing in a joint division fantasy football league and visiting Afghan orphanages. He would retreat back to his barracks late at night to make calls back to South Bend. “I wanted to be a good enough officer so even my roommate had no idea what my day job was,” Mr. Buttigieg said.

Google made this wish unattainable. “When I got there, I may have had more to prove to demonstrate that I was there to get the job done,” he said.

As a candidate, Mr. Buttigieg does not lead with his veteran status, but rather sprinkles it through his conversation, a hint of flavor that is meant to be noticed, and the result of careful mental spade work meant to extrapolate his experiences into his political identity.