President Obama eulogizes Beau Biden in Wilmington, Del., on Saturday. He said Beau Biden brought to his work and family “a mighty heart.” (AP)

President Obama was visibly distracted.

“He was just staring out the window, and it was clear he wasn’t paying attention,” recalled David Axelrod, who was serving as a White House senior adviser at the time.

It was May 2010, and Vice President Biden’s older son, Beau had just suffered a stroke. “ ‘I don’t know how Joe’s going to go on if this doesn’t work,’ the president said,” Axelrod recalled. A week later, when Biden returned to the West Wing, Obama sprinted out of his office to welcome him back.

Five years later, as Biden dealt with the prospect that Obama dreaded, he asked the president to deliver a eulogy for his son, to take on the task of giving voice to the intense private grief of a family that has spent decades in the limelight.

Biden’s request underscored just how much the personal relationship between the two men has evolved in the seven years since they forged their political partnership.

Within a matter of 48 hours, members of the Obama and Biden families went from the Sidwell Friends middle-school graduation ceremony — Biden’s granddaughter Maisy is in the same grade as Sasha Obama, and the girls are close friends — to mourning Beau Biden together in Wilmington.

“It is a really meaningful family relationship,” said Ron Klain, who served as Biden’s chief of staff during the first term and as the president’s coordinator for the Ebola epidemic in the second term.

The partnership has not been without its rough patches. Biden, notorious for speaking off-the-cuff, got into trouble during the 2008 primaries for telling a crowd that Obama would be “tested” by other foreign leaders because of his youth. In May 2012, he forced the president’s hand on same-sex marriage, after unexpectedly telling an interviewer he was “absolutely comfortable” with such unions. Three months later, he raised eyebrows when he told a racially mixed audience in Virginia that GOP presidential candidate Mitt Romney’s approach to regulating Wall Street would “put y’all back in chains.”

But these moments of tension have not altered a fundamental dynamic between two men who have become partners in governing as well as close confidants.

“They trust one another and can be very honest with each other,” White House senior adviser Valerie Jarrett said in an interview, adding: “They love each other.”

The contrast between Obama, the disciplined, methodical thinker, and Biden, the back-slapping, emotional Irish American pol, has been evident from the outset. It has become a source of amicable teasing, such as when they toured a plant in Clinton, Tenn., and saw a blue sports car manufactured with a 3-D printer.

Vice President Biden gave a heartfelt speech on dealing with the loss of a loved one to military families and friends at the annual TAPS National Military Survivor Seminar in 2012. (YouTube/Tragedy Assistance Program for Survivors)

“We lost Joe’s attention when we laid eyes on that 3-D-printed sports car,” the president said, drawing laughter from the crowd. “And we had to explain to him: You don’t get to drive on this trip.”

Julie Smith, who served as Biden’s deputy national security adviser between 2012 and 2013, said that Biden “has learned to adapt to the president’s style” even as the president has come to accept his second-in-command’s quirkier approach.

“They’ve found a way to manage their differences,” said Smith, who directs the strategy and statecraft program at the Center for a New American Security. “They don’t have to lose sleep over this relationship, because they’re going to make it work.”

The massive financial challenges that the administration faced in its early days, Axelrod and Jarrett said, helped forge a closer rapport between Obama and Biden. They have a private lunch together once a week, Biden regularly attends the president’s daily intelligence briefing, and Obama has tasked the vice president with major initiatives, such as managing the U.S. relationship with Iraq and implementing the $787 billion economic stimulus package.

“We came to office at such a miserably difficult time and had to face some very difficult challenges, and I think that’s part of what forged that relationship,” Axelrod said in the interview Friday. “It was in this crucible of crisis where they really had to rely on each other.”

At times, according to several current and former officials, Biden has served as the president’s foil. Former White House press secretary Jay Carney, who served as Biden’s spokesman for two years before serving in that position, recalled attending a meeting in 2011 in the Roosevelt Room where roughly a dozen advisers had reached a consensus on the matter in question before the vice president said that he disagreed.

“The vice president finished, and the president said, ‘I think Joe’s right,’ ” Carney said, adding that on such occasions Biden “created space for the president to take a contrarian view and created more room for his decision-making.”

Biden also has taken on unenviable assignments, including working to ease tensions between Obama and House Democrats, negotiating fiscal deals with Senate Majority Leader Mitch McConnell (R-Ky.) after Republicans made major electoral gains and attempting to broker peace in the Middle East and in Ukraine.

But Biden has not been a freelancer during his time in the White House, and his intense loyalty to the president has earned him considerable affection not just from Obama but also other top aides. The warmth of the Obama-Biden relationship stands in contrast to the last Democratic administration, when President Bill Clinton and Vice President Al Gore established an early collaborative relationship that eventually frayed because so much of the second term was colored by Gore’s presidential ambitions.

“That made it inherently transactional in some ways,” said a former senior administration official, who knows all four men. “Every day, they were negotiating the goals of the Clinton presidency and the goals of making the vice president the next president.”

Biden has said that he will declare sometime this summer whether he will run in 2016, but it appears increasingly unlikely that he will pursue the presidency one more time. And regardless of what path he takes, the official added, “he hasn’t built his vice presidency around becoming president.”

And it helps explain why on Saturday, Obama delivered an emotional eulogy in which he declared from the pulpit of Wilmington’s St. Anthony of Padua Church to Beau Biden’s widow, Hallie, his two children and the rest of the family assembled there, “We are here to grieve with you, but more importantly, we are here because we love you.”

“To Natalie and Hunter — there aren’t words big enough to describe how much your dad loved you, how much he loved your mom. But I will tell you what, Michelle and I and Sasha and Malia, we’ve become part of the Biden clan,” he said. “We’re honorary members now. And the Biden family rule applies. We’re always here for you, we always will be — my word as a Biden.”