Joe Biden’s long advocacy for gay rights reached a historic moment when the president-elect named former South Bend, Ind., mayor Pete Buttigieg as his transportation secretary. If confirmed, Buttigieg will become the first openly LBGTQ Cabinet member. But Biden’s support of the gay community has at times caused a stir. At a sensitive moment in 2012, then-Vice President Biden inadvertently prodded his boss, President Barack Obama, to speed up his public affirmation of same-sex marriage.

The official launch of Obama’s reelection campaign was slated for the first weekend in May 2012. First, Obama was to hold back-to-back rallies on Saturday, May 5, in the battleground states of Ohio and Virginia. Then, on Sunday, Vice President Biden was to hit the airwaves on NBC’s “Meet the Press.”

Biden, known for going off-script, had been rigorously prepped and reminded of his mission: Stay on message.

When he took his seat on the set of NBC’s Washington studio, Biden projected the image of the president’s lieutenant in a crisp charcoal suit, white shirt and blue-striped tie. But when host David Gregory asked about a sensitive unresolved issue hanging over the administration, Biden veered from the campaign playbook. “You know,” Gregory began, “the president has said that his views on gay marriage, on same-sex marriage, have evolved. But he’s opposed to it. You’re opposed to it. Have your views … evolved?”

Biden acknowledged that he had indeed evolved on the issue — faster and further than the president. Several weeks earlier, Biden had admitted in a private meeting in Los Angeles with 30 advocates for gay and lesbian rights that his view differed from Obama’s, and he’d told the group that he had to keep his opinion to himself. But now, on national television, he spoke from the heart.

“Look,” Biden began. “I just think — that — the good news is” — he set his elbows on the table and interlaced his fingers, almost prayerlike. Same-sex marriage, he explained, came down to “a simple proposition: Who do you love?” He repeated it for emphasis: “Who do you love? And will you be loyal to the person you love?” He explained that most people believed that was what all marriages were about, “whether they’re marriages of lesbians or gay men or heterosexuals.”

Realizing he’d strayed into controversial territory, Biden stressed he was speaking for himself personally, not for the White House. “I — I — look, I am vice president of the United States of America. The president sets the policy,” he observed. And he elaborated on his own view: “I am absolutely comfortable with the fact that men marrying men, women marrying women, and heterosexual men and women marrying another” — he slowed down now to make his point perfectly clear — “are entitled to the same exact rights, all the civil rights, all the civil liberties. And quite frankly, I don’t see much of a distinction beyond that.”

The Obama team’s carefully choreographed campaign kickoff had suddenly exploded: The vice president had announced, on live TV, that he favored same-sex marriage while the president, as everyone knew, lagged behind him. In their book, “Double Down: Game Change 2012,” Mark Halperin and John Heilemann reported the shock of David Plouffe, Obama’s 2008 campaign manager who was now a senior adviser to the president. When Plouffe read the transcript of Biden’s “Meet the Press” interview, he cried: “What the f---? How can this have happened?”

What made Biden so appealing — that on the public stage he was more heart than sense — also made him infuriating. In his most authentic moments, the polished senior politician was not much different from the impulsive, sometimes reckless, schoolboy he once was. Back in Scranton, Pa., at age 8 or 9, Joey accepted a dare from a friend to run under a dump truck as it moved slowly back and forth at a construction site. The friend never thought Joey would do it, but young Biden was fearless. “The dump truck was loaded to the gills and backing up — not too fast — and Joey was small,” wrote Richard Ben Cramer in “What It Takes,” his 1992 book on presidential politics, “and he ran under the truck from the side, between the front and back wheels … then let the front axle pass over him. If it touched him, he was finished — marmalade — but Joey was quick. The front wheels missed him clean.” In his portrait of Biden’s abortive run for the presidency in 1988, Cramer saw the child in the adult: “Joe Biden had balls. Lots of times, more balls than sense.”

After his unequivocal declaration on same-sex marriage, Biden told Gregory about that private meeting he had had with gay advocates in Los Angeles. During the meeting’s question-and-answer period, Biden recounted, one of the men wanted to know: “Let me ask you, how do you feel about us?”

In reply, Biden singled out a gay couple at the meeting. He had visited the two men in their home and met their two adopted children, and when he had walked into the house, the kids, ages 7 and 5, had handed Biden flowers. The vice president repeated for the national television audience what he had said to those two men at the private meeting: “I wish every American could see the look of love those kids had in their eyes for you guys. And they wouldn’t have any doubt about what this is about.”

Biden’s remarks put Obama in a tough position. Plouffe feared the political repercussions of the president altering his view on gay marriage, and he had persuaded Obama to keep quiet on the issue. In Plouffe’s estimation, a direct Obama statement favoring gay marriage was too risky ahead of the 2012 general election.

Over the years Obama had shifted his stand on the issue. In Chicago in 1996, when he ran for an Illinois state Senate seat, he told a gay newspaper in a questionnaire that he favored legalizing same-sex marriage. But in 2004 as a U.S. Senate candidate he asserted that marriage was something just for a man and a woman. In 2008, on the presidential campaign trail, he took an official position against a change in marriage rights, though he let it be known among his confidants that his views were evolving.

By 2011 — while in the White House — he had come around: He privately told his advisers he approved of gay marriage. But for public circulation, his aides wanted only to promote the line that he was “evolving.” To some liberals, Obama’s reticence reflected a lack of political courage. Obama “has liberal instincts and will effectuate progressive reforms,” wrote Harvard law professor Randall Kennedy in his book “The Persistence of the Color Line,” “but only if he can do so without getting uncomfortably close to what he perceives to be too high a political price.”

As president, Obama demonstrated his sympathy for the rights of the gay community. He led and won the repeal of the Clinton-era “don’t ask, don’t tell” policy, which denied openly gay Americans the right to serve in the military. Obama also ended the Justice Department’s legal defense of the 1996 Defense of Marriage Act, which defined marriage as a union of a man and a woman and allowed states to refuse to recognize same-sex marriages attained in other states; the Supreme Court would rule the law unconstitutional in 2013.

Obama chafed at his own lack of authenticity on gay marriage. His wife, Michelle, and his longtime friend and adviser Valerie Jarrett told him to disregard the politics and simply declare publicly what he felt. David Axelrod, the chief strategist for both Obama presidential campaigns, and Dan Pfeiffer, a senior presidential adviser, counseled the president that voters responded better to a candidate who delivered his own unvarnished truth.

Before Biden went on “Meet the Press,” the White House had been considering ways for Obama to speak his mind. Aides had drawn up an elaborate strategy allowing the president to seize on gay marriage as a major civil rights issue. A blueprint for his announcement had slowly come together. The game plan had the president appearing at an LGBT event in New York on May 14 followed by a visit to ABC’s daytime talk show “The View” to reveal his change of heart. “I was just maniacal about order and planning,” Plouffe explained in “Obama: An Oral History 2009-2017″ by Brian Abrams. He recognized that a historic moment lay before the president. “I wanted it to be the president’s moment.”

But the choreographed scenario Plouffe and others had put together crumbled as soon as Biden spoke honestly on “Meet the Press.” The media reaction was swift and overwhelming. The Associated Press declared, “Obama’s Vague Gay Marriage Stance Under Scrutiny.” The Boston Herald warned, “Veep’s Marriage ‘Gaffe’ an Issue for Prez.”

While Obama’s aides railed over Biden, the president was more annoyed at the appearance of White House chaos than at Biden’s remarks, for he knew his sentiments were in concert with the vice president’s. By Monday, the White House was losing control of the issue. Obama’s advisers watched aghast as Education Secretary Arne Duncan echoed Biden’s view on MSNBC’s “Morning Joe” political talk show. When asked if he believed that same-sex men and women should be able to get legally married, Duncan promptly replied: “Yes, I do.”

When asked, “Have you ever said that publicly before?” Duncan answered bluntly: “I don’t know I’ve ever been asked publicly.”

For the interview, Duncan sat in a studio in Washington, taking the questions through an earpiece. His staff was standing by listening to his answers but couldn’t hear the questions. The words same-sex marriage never came out of the education secretary’s mouth. Afterward, Duncan recalled, his staff walked out with him and said, “Oh, that interview went really well.”

Duncan had no idea he’d stepped into a minefield. He hadn’t watched the Sunday talk shows and missed the ensuing brouhaha. Reflecting later, Duncan said he was pleased at the way he answered the unexpected question. Like Biden, he’d spoken from the heart. “I did it without thinking,” he said. “I was actually very relieved that I just told the truth.” He didn’t want to sound like a Washington politician who equivocated or dodged an issue. “That’s not who I wanted to be,” he said.

But soon enough he realized his role in the rising storm. Now both Biden and Duncan inadvertently had pressured the president on same-sex marriage. “It may have caused short-term pain,” Duncan observed. “But I knew where the president’s heart was on this. You know, he hadn’t said it publicly, but I knew down deep exactly what he thought. Frankly I think the vice president and I actually accelerated getting him to where his heart was.”

The president and his aides had not yet sorted out their strategy. On Monday, press secretary Jay Carney gave an uncomfortable briefing at the White House where his reply to reporters’ questions was a monotonous: “I have no update on the president’s personal views.”

On Tuesday, the president’s staff — realizing his silence was untenable — reached out to Robin Roberts, anchor of ABC’s “Good Morning America.” The president, Roberts was informed, wanted to tape a one-on-one interview with her the following day — but what exactly the president wanted to say wasn’t made clear.

In the Cabinet Room on Wednesday, Obama and Roberts sat in facing leather chairs. The setting evoked the grandeur of governance and important decisions: gold curtains at the white French doors, a bust of Benjamin Franklin presiding from a corner. Obama, looking presidential in a blue suit, had an American flag over his shoulder, and a view out a window showed the peaceful White House grounds.

Roberts asked the question of the moment: “Mr. President, are you still opposed to same-sex marriage?”

His answer was so striking — coming from a sitting president — that ABC News broke into the network’s afternoon programming with a special report, anchored by George Stephanopoulos and Diane Sawyer. Sawyer announced, “Big breaking news from the White House. This is a historic political and cultural moment in this country, and the issue: gay marriage.”

The anchors then cut to Roberts stationed after the interview in front of the White House. She provided a little background on the week then Obama came on the screen, his voice calm and reflective, quite in contrast to the hysterics of the past three days: “I have to tell you, as I’ve said, I’ve — I’ve been going through an evolution on this issue. I’ve always been adamant that gay and lesbian Americans should be treated fairly and equally. … I’ve stood on the side of broader equality for the LGBT community. And I had hesitated on gay marriage — in part, because I thought civil unions would be sufficient. … But I have to tell you that over the course of several years, as I talk to friends and family and neighbors. When I think about members of my own staff who are incredibly committed, in monogamous relationships — same-sex relationships — who are raising kids together. When I think about those soldiers or airmen or Marines or sailors who are out there fighting on my behalf and yet feel constrained … because they’re not able to commit themselves in a marriage. At a certain point, I’ve just concluded that, for me personally, it is important for me to go ahead and affirm that I think same-sex couples should be able to get married.”

The president’s shift on same-sex marriage was promptly sucked into the journalistic maw — reported, debated, discussed in print, online and on television. NBC broke into its regular programming, running its competitor’s scoop. CNN also rushed onto the air with its “Breaking News” logo accompanied by a sizzling sound and Wolf Blitzer crying out, “Truly historic and potentially watershed moment. … With the election less than six months away, the political implications are enormous.”

The next day, “Good Morning America” aired a clip of Roberts and the president strolling along the White House colonnade, birds chirping loudly in the background.

Roberts asked about Biden’s remarks the previous Sunday: “Did he jump the gun a little here?”

Obama seemed unperturbed, noting that he’d already decided to announce his position before the election. He lightly chastised his vice president, and in a way that revealed what he understood about Biden. Certainly the vice president was impetuous, but, the president knew, Joe cared deeply about the way Americans were treated.

Barack said of his friend, “He probably got out a little bit over his skis — out of generosity of spirit.”

Plouffe’s consternation over the political risk to the president turned out to be unfounded. In his ingenuous way, Biden had nudged the president to fall in line with the mood of the country. A Gallup poll that week found that 50 percent of Americans said they supported legal rights for gays wishing to marry; 65 percent of Democrats and 57 percent of independents agreed, while 22 percent of Republicans approved.

As president, Obama now owned the issue. If Biden had stolen his thunder briefly, the vice president now receded into the background. By speaking up, Biden had thrown a sharp spotlight on the civil rights of gays. But now the accolades were all Obama’s. “It has always taken strong national leadership to expand equal rights in this country,” the New York Times wrote, “and it has long been obvious that marriage rights are no exception. President Obama offered some of that leadership on Wednesday.”

During her interview, Roberts had asked the president, “So you’re not upset with anybody?”

Acknowledging the bumps along the way, Obama said he would have preferred to have had it all evolve a little more smoothly.

“But,” he added, “all’s well that ends well.”

Steven Levingston is nonfiction editor of The Washington Post and author of “Barack and Joe: The Making of an Extraordinary Partnership,” from which this article has been adapted.