Barack Obama and Hillary Clinton wave to the crowd during a campaign rally in Orlando, Florida, during Obama's first presidential campaign, Oct. 20, 2008. REUTERS/Jim Young

President Barack Obama formally endorsed Hillary Clinton for president Thursday, confirming what most have long believed was his preference for his former secretary of state in the Democratic primary contest. Clinton’s campaign announced the endorsement on Twitter along with a video of the president giving her high praise.

“I don’t think there’s ever been someone so qualified to hold this office,” Obama said in the video. “She’s got the courage, the compassion and the heart to get the job done.”

This has been a pretty consistent message from Obama over the past several months. Even when Clinton’s rival, Sen. Bernie Sanders, was at his strongest point, Obama emphasized his history with Clinton and made sure to point out the positives he saw in her.

In January, for example, he told Politico’s Glenn Thrush that Clinton had many years of experience, which was why she sometimes seemed to receive more criticism than Sanders, who was new to most voters.

“I've gotten to know Hillary really well, and she is a good, smart, tough person who cares deeply about this country,” Obama said.

Now that the president has endorsed Clinton and said he will campaign with her against presumptive Republican nominee Donald Trump, he is likely to be quite helpful to her on the campaign trail. But this chummy relationship did not always prevail between Obama and Clinton.

When the two ran against each other in the 2008 Democratic primaries, they waged a tough fight, with jabs just as harsh as those exchanged between Sanders and Clinton this year. Clinton consistently criticized Obama for not having enough experience and not using consistent messaging during his campaign, while Obama painted Clinton as a “corporate lawyer sitting on the board at Walmart” and famously cracked in a debate that he was “likable enough.”

As Obama picked up momentum and Clinton struggled that year, she and her husband were accused of being overly dismissive and using racially coded attacks against the freshman senator from Illinois.

When Clinton finally conceded to Obama in the summer of 2008, her supporters were just as upset as many Sanders backers are this year. There were concerns that Clinton-Obama animosity would overshadow the general election, and a CNN primary exit poll conducted in May of that year found that half of Clinton’s supporters in Indiana said they would not vote for Obama in November. (Obama carried Indiana in 2008, the only time it's gone Democratic since 1964.)

Of course, the two candidates reconciled and Clinton went on to campaign for Obama and then serve in his Cabinet as secretary of state. But some Obama supporters were surprised at the choice, they told NPR this week, thinking the campaign tension might be too much to overcome.

Instead, both of them worked to mend their relationship. “She could not have been more warm. She could not have been more gracious,” Obama speechwriter Ben Rhodes told NPR about Clinton when she entered the Obama administration.

Speaking about Obama’s endorsement of Clinton’s 2016 presidential bid on Thursday, White House press secretary Josh Earnest said he saw parallels between 2008 and this year.

“There’s some relevant history here. Secretary Clinton was not in such a different position from the one facing Sen. Sanders today,” Earnest told reporters. “She was proud of the strong support that she got from voters all across the country, but she also made it clear that then-Sen. Obama was the best opportunity that our country had to advance the priorities she’d been campaigning on.”

Obama met with Sanders Thursday morning and Earnest said the Vermont senator was not surprised the president planned to endorse Clinton. Earnest added that Obama was respectful of Clinton’s supporters after she lost the 2008 primary, and emphasized that the same type of respect for Sanders' followers would be important this year.

Barack Obama Endorses Hillary Clinton | InsideGov

Clinton became a loyal member of Obama’s White House and largely embraced his policies during her tenure. Since entering the 2016 presidential race, Clinton has found herself needing to separate from a few of Obama’s policies even as she embraces his legacy in the hopes of winning over the coalition that got him elected.

Last fall, she came out against the Trans-Pacific Partnership trade deal, a pet project of Obama’s, and then in January she called on the president to end deportation raids aimed at sending immigrants back to Central America. Both the TPP and the raids were also criticized by Sanders, and Clinton’s policy changes were seen as moves to attract progressive voters this year.

Still, she and Obama remain close despite those disagreements and seem to have largely smoothed over any ruffled feathers left from their 2008 clashes. At this point, their relationship has evolved into one that can help them both succeed politically, with Obama looking to protect his legacy and Clinton keeping her sights on the White House as they take on Trump.