WASHINGTON — President Obama told Senator Bernie in an Oval Office meeting on Thursday to channel the energy of his presidential campaign’s millions of supporters behind Hillary Clinton, and said that Mr. Sanders would play a central role in shaping the Democratic agenda if he did.
Less than an hour and a half later, Mr. Obama, who had tried to remain neutral in the race between Mr. Sanders and Mrs. Clinton, formally endorsed her.
Moving swiftly to unite his party after a primary campaign that has left many of Mr. Sanders’s supporters bitter and disillusioned, Mr. Obama, according to his aides, tried to mollify the maverick senator while prodding him to reorient his efforts against Mrs. Clinton into a broader bid to help Democrats in November.
There was no hint after the meeting that Mr. Sanders intended to challenge Mrs. Clinton for the nomination at next month’s convention, but hours later at a rally in Washington he urged voters there to go to the polls in their primary on Tuesday and to keep pushing for a political revolution.
After the White House meeting, Mr. Sanders vowed to take the ideas that have animated his campaign — addressing poverty and income inequality, increasing Social Security benefits, and reducing the role of money in politics — to the convention.
But he also announced plans to meet soon with Mrs. Clinton to discuss ways they could work together to defeat Donald J. Trump, the presumptive Republican presidential nominee.
The meeting was the set piece of a day of choreographed political theater in which Democrats treated Mr. Sanders to a visit only slightly less elaborate than that of a head of state. The White House made sure that cameras were positioned to capture the president and the vanquished Vermonter strolling animatedly along the White House colonnade to the Oval Office for their meeting. Later, Mr. Sanders met with the Senate Democratic leadership before zooming up Massachusetts Avenue for an audience with Vice President Joseph R. Biden Jr. at his residence at the Naval Observatory.
Democrats were hoping that if they gave time and space to Mr. Sanders, he would not cause trouble for them at their convention in Philadelphia and would eventually endorse Mrs. Clinton. But Mr. Sanders spent much of his day using back entrances and side doors and ducking into stairwells to avoid reporters’ questions, clearly unwilling to talk in precise terms about his plans.
The road ahead was clearer for Mrs. Clinton, who on Thursday collected long-anticipated expressions of support from influential Democrats, including Senator Elizabeth Warren of Massachusetts, perhaps more of a favorite of the party’s liberals than even Mr. Sanders.
In a video posted on her campaign’s Facebook page shortly after Mr. Sanders departed the White House grounds to visit the Capitol, Mr. Obama described Mrs. Clinton as the most qualified candidate to seek the White House, and implored Democrats to come together to elect her after a divisive party primary.
“I don’t think there’s ever been someone so qualified to hold this office,” Mr. Obama said in the three-minute statement.
Mr. Obama has made no secret of his desire to play an active role in the race to succeed him. “I’m with her, I am fired up, and I cannot wait to get out there to campaign for Hillary,” Mr. Obama said in the video.
Mrs. Clinton immediately announced that she and the president would hold their first joint campaign appearance of the 2016 race on Wednesday in Green Bay, Wis., the start of what White House officials said would be an intense campaign push for Mr. Obama that will culminate in near-daily appearances as the November election draws nearer.
White House officials had been discussing the endorsement with Mrs. Clinton’s camp for days, but they kept the timing under wraps, in part as a gesture of respect for Mr. Sanders and his highly motivated supporters.
Mr. Obama told Mr. Sanders on Sunday that the endorsement would come soon, according to people familiar with the conversation, and discussed the announcement with Mrs. Clinton on Tuesday, the night she clinched the nomination.
Mr. Obama recorded the Facebook message earlier on Tuesday at the White House, aides said.
The president had been circumspect about declaring the race finished, even after Mrs. Clinton captured sufficient delegates in primaries on Tuesday to clinch the Democratic nomination. On Thursday, he congratulated her on “making history” and said he had personally witnessed her qualifications for the Oval Office.
“She’s got the courage, the compassion and the heart to get the job done,” he said. “I have seen her judgment, I’ve seen her toughness, I’ve seen her commitment to our values up close.”
Mr. Obama also praised Mr. Sanders for what he called an “incredible campaign.” He said the Vermont senator’s emphasis on addressing income inequality, reducing the influence of money in politics and bringing young people into the political process would strengthen the party.
In their Oval Office meeting, White House officials said, Mr. Obama told Mr. Sanders that he could play a valuable role in re-energizing the party by supporting Democrats in races across the country this year, and use the influence he has amassed in his campaign to press his agenda forward in the Senate.
Mr. Sanders, speaking to reporters as he left the West Wing with his wife, Jane, said that “we will continue doing everything that we can to oppose the drift which currently exists toward an oligarchic form of society where a handful of billionaires exercise enormous power over our political, economic and media life.”
“Needless to say,” he added, “I am going to do everything in my power and I will work as hard as I can to make sure that Donald Trump does not become president of the United States.”
Mr. Obama’s quick endorsement irritated some of Mr. Sanders’s leading supporters, who said they could not understand why the president would not wait until after next week’s Washington primary, the last contest in the Democratic nominating process, to weigh in.
“I thought they’d give him the grace to finish out what he pledged to do, which is take his campaign to the final contest,” said Paul G. Kirk, a former Democratic National Committee chairman and Massachusetts senator who backs Mr. Sanders.