WASHINGTON — Deval Patrick was in need of a pep talk.

He was staring down reelection as Massachusetts governor in 2010, in the midst of a sluggish economic recovery that would ultimately contribute to sweeping Democratic defeats across the country. In stepped President Barack Obama, a close friend and political ally, who was in town for an event. The two men met for a “get in the game” conversation that helped put Patrick on the path to a second term.

“I think it was very meaningful to Deval,” said David Axelrod, a political adviser to both Obama and Patrick. “That’s the kind of relationship they have. There’s a level of trust and mutual caring between them.”

That relationship will test whether Obama can maintain his vigorously neutral approach to the 2020 Democratic primary now that Patrick has launched a late bid for the presidential nomination. Although Obama has ties to several candidates — most notably Joe Biden, who spent eight years as his No. 2 in the White House — his ties to Patrick are unique. The two men were friends well before the White House years and have bonded over shared personal experiences and a strikingly similar approach to politics.

“They both had Chicago roots, they both had the Harvard experience and they shared a set of values,” Axelrod said. “You go back and listen to some of Patrick’s speeches from when he was running for governor and you hear echoes of Obama.”

Obama advisers say there are currently no plans for the former president to endorse in the Democratic primary race, though he’s met with most of the major candidates and is said to be following the primary campaign closely. Yet advisers have purposely left some wiggle room in that position, well aware that there could be a moment that demands the input of the nation’s most popular Democrat, particularly if the primary appears to be headed toward a contentious conclusion.

For now, the former president appears content to stay on the sidelines and offer occasional counsel to the candidates he is closest to, including Patrick.

When Patrick called him this week to tell him he was making a late bid for the nomination, he got advice similar to what Obama has told other White House hopefuls: Make an affirmative case for yourself, show up and be present even in places you might lose, and stay focused on the urgency of defeating President Donald Trump.

Patrick, who made his first campaign appearance in New Hampshire on Thursday, said Obama had given him “great insights about his own experiences and about his experience with some of the other candidates and what he thought the strengths and weaknesses of the campaign, of my campaign, might be.”

“He’s been, I think, entirely appropriate in saying, Look, this is your decision, no one else’s,” Patrick said shortly after filing papers to get on the ballot in New Hampshire. “And I’m not encouraging you or discouraging you. Be clear-eyed about how heavy the lift is.”

Obama and Patrick first connected in the 1990s, long before either was a national political figure. Both graduated from Harvard Law School and were shaped by their experiences on the South Side of Chicago, where Patrick grew up and Obama worked as a community organizer. Later, when Obama and his family vacationed during their summers in the White House at Martha’s Vineyard, Patrick and his family made regular visits from Boston.

As barrier-breaking African Americans, Obama and Patrick have also drawn comparisons throughout their political careers. The day after Patrick won his first campaign for governor in 2006 — running on a “Together We Can” slogan — two of his top political consultants, Axelrod and David Plouffe, met with Obama to start charting his 2008 presidential campaign. That campaign’s motto: “Yes We Can.”

In addition to Axelrod and Plouffe, Obama confidante and White House senior adviser Valerie Jarrett is particularly close to Patrick and urged his campaign for president.

It’s unclear whether those connections will help Patrick, who is launching his campaign less than three months before voting begins. Many Obama staffers are already working for other candidates or have left the political arena. It’s also uncertain whether Patrick, who was the first black governor of Massachusetts, will be seen by African American voters as the heir to Obama’s legacy.

So far, it’s Biden who has had the strongest appeal with black voters, one of the most important constituencies in Democratic politics. And it’s Biden who has wrapped himself in Obama’s legacy, frequently reminding voters of the eight years he spent by the 44th president’s side. He’s also staked his candidacy in part on a robust defense of the landmark health care overhaul Obama signed into law.

Obama has stayed in touch with Biden throughout the campaign, and the two huddled privately last month at funeral services for U.S. Rep. Elijah Cummings of Maryland.

Biden also remains the only candidate whose entry into the race was greeted with a formal statement from Obama, who praised his former vice president but stopped short of endorsing his White House run.