Portsmouth, New Hampshire (CNN) Hillary Clinton and Bernie Sanders formally declared an end to their political rivalry Tuesday, joining forces to take on a shared enemy: Donald Trump.

"I have come here to make it as clear as possible why I am endorsing Hillary Clinton and why she must become our next president," Sanders said at a joint rally here. "Secretary Clinton has won the Democratic nomination and I congratulate her for that."

The 74-year-old self-described democratic socialist, who has been a thorn in Clinton's side over the last year, pledged to support his former rival through Election Day: "I intend to do everything I can to make certain she will be the next president of the United States."

But there appeared to be little natural chemistry between Clinton and Sanders and their body language was noticeably stiff. The two avoided physical contact after first walking on stage together, and Sanders, in his 30-minute speech, repeatedly mentioned Clinton by name without acknowledging that she was standing next to him looking on.

After concluding his speech, Sanders appeared to move in for a handshake -- which Clinton ignored by stretching out her arms and offering a hug, instead.

"We are joining forces to defeat Donald Trump!" Clinton declared. "I can't help but say how much more enjoyable this election is going to be when we are on the same side. You know what? We are stronger together!"

And even as she struck a victorious tone, Clinton also repeatedly and directly addressed the Sanders supporters in the high school gymnasium.

She walked through a number of policy issues where Sanders had pulled her to the left during the course of the election -- minimum wage; the Trans-Pacific Partnership trade deal, college affordability -- to make a broader concession: the movement that Sanders created was nothing short of a political revolution.

"Sen. Sanders has brought people off the sidelines and into the political process. He has energized and inspired a generation of young people who care deeply about our country," she said. "To everyone here and everyone cross the country who poured your heart and soul into Sen. Sanders' campaign: Thank you."

The long-anticipated unity event, coming less than two weeks ahead of the Democratic National Convention, effectively puts to rest Democratic fears of a political nightmare scenario: that Sanders might sit on his hands in the general election, or worse, run as a third-party candidate on the left.

Clinton aides are confident that Sanders -- who excited the liberal base and won young voters by large margins during the primary -- could be a potent weapon against Trump and help Clinton rev up liberal voters.

But even at an occasion meant to turn the page on their primary battle, Sanders reminded Clinton, who stood next to him on stage, of the millions of Americans who had rejected her.

"Let me begin by thanking the 13 million Americans who voted for me during the Democratic primaries," Sanders said. "Our campaign won the primaries and caucuses in 22 states, and when the roll call at the Democratic National Convention is announced, it will show that we won almost 1,900 delegates."

Tuesday's event is the byproduct of weeks of conversations between Robby Mook, Clinton's campaign manager, and Jeff Weaver, Sanders' top and most trusted aide.

Aides and advisers said that while Sanders and Clinton's June meeting in Washington, D.C., laid the groundwork for the New Hampshire event, it was Mook and Weaver who made the cooperation between the campaigns possible. After Clinton and Sanders left their meeting at the Hilton, Mook and Weaver stayed for two hours to discuss how to work together.

The two campaign managers would continue to talk daily, a Clinton aide said, and Mook traveled to Burlington, Vermont -- where Sanders' campaign is headquartered -- last month so that the two could meet at the Farmhouse Tap and Grill to continue their work together.

With Mook munching on a salad and Weaver eating a burger, the two hammered out how Clinton and Sanders could come together for an event like Tuesday's rally - and how the rivals could work together going forward. Mook also began working directly with Jane Sanders, the senator's wife, in the lead up to policy Clinton's announcements on college affordability and healthcare that moved her closer to Sanders' positions.

Tuesday's endorsement will help Clinton "enormously," said former Massachusetts Rep. Barney Frank, a Clinton supporter who co-chairs the party's Rules Committee.

And in a nod to Sanders's successful fundraising efforts that brought in millions of dollars from small donors, with at one time an average donation of $27, Clinton's campaign has made $27 an option on its online donor page

Hard feelings still persist among Sanders backers

But converting all Sanders fans may be impossible.

"Given, frankly, some of the criticism that he made, I think it will take work to get all of them there," Frank said.

At the rally, where both Sanders and Clinton signs, T-shirts and buttons dotted the crowd, there were plenty of Sanders loyalists who said they are not sold on Clinton -- and might never convert.

Marie Clark, a Sanders supporter from Laconia, New Hampshire, said she remains devoted to Sanders -- or no one. "I'm Bernie or Bust," said Clark, who plans to write Sanders in.

Asked whether she thought that would help Trump, she said, "I think people need to vote for something rather than against something."

"I want to vote for someone who has integrity, someone who has been consistent for 40 years," Clark said. "I will always support a political revolution."

Patti Covino drove from Vermont to attend Tuesday's event and held a sign that read: "Only Bernie."

"I would follow Bernie to the ends of the earth, but I will never follow him to Hillary," Covino said. "I'm not voting for Trump, I will write Bernie in. It doesn't matter what he says."

Trump has sought to appeal to Sanders supporters, saying he better represents Americans angry at the political establishment than Clinton does. Clinton believes Sanders can capture those attracted to Trump, especially in states the senator won such as New Hampshire, Michigan and Wisconsin.

In advance of the event, Trump criticized the endorsement on Twitter, saying Sanders, "totally sold out to Crooked Hillary Clinton."

"I am somewhat surprised that Bernie Sanders was not true to himself and his supporters. They are not happy that he is selling out!" Trump tweeted.

I am somewhat surprised that Bernie Sanders was not true to himself and his supporters. They are not happy that he is selling out! — Donald J. Trump (@realDonaldTrump) July 12, 2016

Responding to another Trump tweet, Sanders's campaign decried the presumptive Republican nominee's "big talk."

Big talk from the same guy who was too afraid to debate Bernie in California. https://t.co/LVCjo0PKrN — Bernie Sanders (@BernieSanders) July 12, 2016

Clinton efforts to appeal to liberals

Sanders' endorsement had been elusive for Clinton long after she clinched the nomination. For weeks, Sanders refused to concede, continuing to hold rallies and advocate for his agenda, rattling Democrats eager to begin the general election.

But with the primary season firmly behind her, appeasing liberals with the help of Sanders and popular Democrats like Massachusetts Sen. Elizabeth Warren and Ohio Sen. Sherrod Brown is now just one piece of her broader challenge of winning over large swaths of the general election electorate, including independents.

On Thursday, Clinton will meet with Senate Democrats at a policy luncheon, a Democratic source said, part of her efforts to coalesce party support around her candidacy.

Clinton's final victory over Sanders comes at the end of a long campaign in which she repeatedly moved to accommodate him and the liberal activists behind his campaign. She reversed her position on sensitive political issues like the Trans-Pacific Partnership trade deal and the Keystone XL Pipeline -- two projects that progressive staunchly oppose.

And last week, Clinton announced a new college affordability plan that mirrored Sanders' proposals. It proposes tuition-free enrollment in public in-state colleges for families making up to $85,000, with the income benchmark increasing to $125,000 over the course of several years.

Sanders also was able to win concessions from Clinton for language in the Democratic party platform last weekend in Orlando, including a provision calling for a $15-an-hour federal minimum wage.

"We got 80% of what we wanted in this platform," Warren Gunnels, a top Sanders foreign policy adviser, told CNN

The perception that Sanders has dragged his feet -- and forced Clinton to move left in a protracted primary race -- has frustrated some Democrats.

Jim Kessler, senior vice president of policy at the centrist Democratic think tank Third Way, said Tuesday's endorsement was weeks overdue.

"The idea of trying to extract concessions out of the nominee when we're going to be in a brutal fight against he most unqualified Republican nominee ever was not helpful," Kessler said. "The middle is where this is going to be fought. So any time that the candidate is being pressed to move to the left, you have to ask: am I going to lose votes in the center?"

Mook and other Clinton aides have worked to win over Sanders supporters as well. Mook held meeting with Sanders' delegates in New Hampshire and Vermont. Marlon Marshall, the campaign's director of States and Political Engagement, traveled to the Wyoming to speak with Sanders delegates there. And Jake Sullivan, Clinton's top policy adviser, spoke with Sanders supporters in Washington state.

Clinton's campaign has also worked to hire Sanders aides. Rich Pelletier, Sanders' deputy campaign manager, started sending Marshall resumes last month and the Clinton campaign in Brooklyn has started to bring on former Sanders aides. Clinton's Vermont and Rhode Island general election campaign managers are both former Sanders staffers, as is Clinton's head of college and university engagement.

One Clinton confidant acknowledged that while Tuesday's event will not be a "panacea" to everything that was said during the primary, everyone involved expects Sanders to be "gracious enough."

Green Party leader: 'Berning hearts are breaking'

Sanders' announcement also marks the senator's decision to join the political establishment rather than shun it. Throughout the primary season, Democratic leaders feared that Sanders would go rogue with his political revolution and launch a third party campaign.

Recently, Green Party presidential candidate Jill Stein had asked Sanders to join forces, even offering him the top spot on the Green Party ticket.

Tuesday morning, Stein began a series of tweets, declaring, "Many Berning hearts are breaking right now."

Many Berning hearts are breaking right now. 💔 — Dr. Jill Stein (@DrJillStein) July 12, 2016

In an interview with CNN on Monday, Stein expressed her disappointment and warned that many Sanders supporters will not jump on Clinton's bandwagon.

"There are a lot of unhappy campers out there who will not follow Sanders back into the graveyard of the Democratic Party," Stein said. "A revolution that goes back under Hillary Clinton's wing is not a revolution."