When candidates at Thursday night’s Democratic debate were asked about their biggest professional setbacks, Mayor Pete Buttigieg of South Bend, Ind., described his experience with coming out as gay.

Hearing such a story on a national stage during a presidential campaign would have been unimaginable just a decade ago, before same-sex marriage was legal and when “Don’t Ask, Don’t Tell” was military policy.

Mr. Buttigieg spoke in detail of his angst over the decision, saying that he worried about coming out at a time when Mike Pence, who has opposed same-sex marriage, was the Indiana governor. (On Friday, the Trump campaign defended the vice president, writing on Twitter that he has “only had nice things to say” about Mr. Buttigieg.)

Mr. Buttigieg said he had feared that coming out would be “the ultimate, career-ending professional setback.” But after serving in Afghanistan as a Navy Reserve officer in 2014, he said, “I came back from the deployment and realized that you only get to live one life, and I was not interested in not knowing what it was like to be in love any longer.”