President Barack Obama said Sunday that he would withhold criticism of the Trump administration once he's out of office — even if President-elect Donald Trump tries to dismantle his legacy.

"I want to be respectful of the office and give the president-elect an opportunity to put forward his platform and his arguments without somebody popping off in every instance," Obama said.

Obama urged his fellow Democrats to try to work with Trump's team if what it's doing is good for the country. But he cautioned that if the Trump administration begins to attack American values, he might be compelled to speak up, and so would the Democratic Party.

"As an American citizen who cares deeply about our country, if there are issues that have less to do with the specifics of some legislative proposal or battle but go to core questions about our values and our ideals, and if I think that it's necessary or helpful for me to defend those ideals, then I'll examine it when it comes," he said.

Speaking at a news conference at the Asia-Pacific Economic Cooperation summit in Lima, Peru, Obama — on his last foreign tour — was at times reflective and humorous, candidly discussing his views on the United States' position as a world leader and touching on the strife within his own party.

Obama reiterated his administration's commitment to policies like the Trans-Pacific Partnership trade agreement and the Paris climate change deal, while doling out advice for the future Democratic leaders.

"I'm not worried about being the last Democratic president, not even for a while," he said. "And I say that not being cute — the Democratic nominee won the popular vote."

He later advised against the apocalyptic tone that has come to characterize the Democratic Party in the wake of Hillary Clinton's loss on Election Night.

Related: China's Xi Calls for 'Smooth Transition' in Relationship With U.S.

"My advice to Democrats is know what you care about and what you stand for and fight for your principles, even if it's a hard fight," Obama said.

President Barack Obama at a news conference Sunday at the conclusion of the APEC Summit in Lima, Peru. Kevin LaMarque / Reuters

"If there are areas where the new administration is doing something that's going to be good for the American people, find a way to work with them," he said. "If you think it's going to be a problem, then say so and make the argument."

Earlier in the evening, Obama met briefly with Russian President Vladimir Putin and, despite what he described as a "candid and courteous" meeting, he said he's not optimistic about the prospects of a Syrian peace agreement in the short term.

Obama said he was "very clear about the strong differences we had on policy."

"The issue of the elections did not come up because that's behind us," he said. Instead, Obama said, he focused on the "bloodshed and chaos" that has destroyed Aleppo and bolstered the Assad regime, and he reiterated the need to arrive at a humanitarian cease-fire in Syria.