WASHINGTON—Sen. Bernie Sanders on Thursday vowed to compete in the final Democratic presidential primary next week in Washington, D.C., but also hinted that he was ready to wind down his candidacy as party officials rallied behind Hillary Clinton.

Mr. Sanders spent the day in Washington, meeting privately with President Barack Obama, Vice President Joe Biden and Senate colleagues. Party leaders urged him to accept defeat and help unite Democrats for the general-election showdown with Donald Trump, the presumptive Republican nominee.

White House press secretary Josh Earnest said Mr. Obama congratulated and complimented Mr. Sanders on his campaign. Mr. Earnest called it “a friendly conversation that was focused on the future.” An hour after the Oval Office visit, Mr. Obama endorsed Mrs. Clinton in a video released by her campaign.

In another sign the party is coalescing around Mrs. Clinton, Sen. Elizabeth Warren (D., Mass.), a hero of the liberal Democratic wing, endorsed the former secretary of state Thursday evening in an interview on MSNBC. Ms. Warren’s endorsement might prove particularly valuable to Mrs. Clinton, given her credibility with the young, liberal voters who gravitated toward Mr. Sanders.

Ms. Warren said Democrats need to be tougher in their dealings with opponents and “ought to be willing to throw a punch.” She added: “There are a lot of things that people say about Hillary Clinton but nobody says that she doesn’t know how to throw a punch.”