WASHINGTON — Senator Bernie Sanders met with President Obama on Thursday and said afterward that he would do everything within his power to stop Donald J. Trump from becoming president — and would work closely with Hillary Clinton to make that happen.

After the meeting with Mr. Obama, which lasted more than an hour, Mr. Sanders gave no indication that he was ready to leave the race just yet, insisting that he would compete in next week’s primary contest here in Washington. However, he made clear that party unity was on his mind.

“I will work as hard as I can, to make sure that Donald Trump does not become president of the United States,” Mr. Sanders told reporters, saying the Manhattan businessman “makes bigotry and discrimination the cornerstone of his campaign” and would be a “disaster” as commander in chief.

He said he would continue fighting for the issues that animated his campaign, including enhancing Social Security benefits, college affordability and restoring the nation’s crumbling infrastructure.