For example, he said, he blamed a dismissive approach to negotiations with President Corazon Aquino of the Philippines for America’s loss of access to important naval and air bases there in the early 1990s. “She was a woman and she was brown,” Mr. Osius said of Ms. Aquino. “And we were smart and arrogant and didn’t listen.”

Years later, Mr. Osius was part of a group of diplomats who quietly pleaded with the George W. Bush administration to engage North Korea through the so-called six-party talks. As the administration’s North Korea policy hardened, he said, two of his colleagues resigned in frustration.

“This is the dilemma that every professional diplomat faces: What ethical lines won’t you cross?” he said. But in that case, “I decided not to quit but to ride it out and see if I could continue to do some good.”

Mr. Osius has spent decades building diplomatic relationships in Vietnam, a one-party state, where he first served as a political officer in the late 1990s. One of his early tasks there was helping to open the United States Consulate in Ho Chi Minh City, formerly called Saigon.

The idea that he would become an ambassador in Vietnam — or anywhere else — was once inconceivable to him, Mr. Osius said, largely because the State Department’s conservative culture made such senior postings effectively off-limits to openly gay American diplomats like himself.

But by 2014, when then-Secretary of State John Kerry recommended him to President Obama as the next ambassador to Vietnam, the agency’s politics had changed.