President Obama is approaching the final weeks of the presidential campaign with an intense sense of urgency and concern amid a growing realization that the election could be determined by the narrowest of margins.

Earlier this year, Obama seemed to regard the defeat of GOP nominee Donald Trump as a near inevitability, but in recent days the president has changed his tone.

His recent warnings to Democrats that Hillary Clinton could lose reflects his understanding that he needs to be personally involved in mobilizing voters in some demographic groups in which he remains more popular than the party’s nominee — including African Americans and young people, according to several Obama aides and outside advisers.

Even though the electoral-college map appears to favor Democrats, strong turnout among minority and young voters in key battleground states is seen as essential to a Clinton victory.

“Preference is one thing, presence is another,” said former White House senior adviser Dan Pfeiffer

President Obama speaks during a campaign event in support of Hillary Clinton in Philadelphia Sept. 13, 2016. (Carlos Barria/Reuters)

The shift in tone was evident Saturday night, when Obama delivered an emotional speech to the Congressional Black Caucus Foundation in which he said it would be “a personal insult, an insult to my legacy” if black voters did not come out in sufficiently large numbers for Clinton in November.

On Sunday, a quieter and more measured Obama struck a similar note at a Manhattan fundraiser for Clinton where he warned Democrats that the deep polarization in the country was making a close election inevitable.

“This should not be a close election, but it will be,” he told the donors as senior members of the Clinton campaign listened. “And the reason it will be is not because of Hillary’s flaws, but rather because, structurally, we’ve become a very polarized society. . . . And so, structurally, we already have these divisions, and it’s going to be hard to overcome those.”

For months, Obama had quietly assured Democratic donors and worried world leaders that voters would reject Trump’s vision of an America in decline. He derided Trump’s lack of knowledge about world affairs and insisted, loudly and publicly, that Trump’s efforts to play on fears of terrorism by calling for a ban on Muslim immigrants would be soundly rejected by voters.

Asked in January if he could imagine Trump delivering a State of the Union address, Obama quipped, “Well, I can imagine it — in a ‘Saturday Night [Live]’ skit.”

He struck the same tone a few months later at a fundraiser in Los Angeles when an alarmed donor pulled him aside and asked if Trump had a serious shot at winning the White House.

“Mr. Trump’s not succeeding me,” he told the contributor at the Los Angeles home of Walt Disney Studios Chairman Alan Horn in April.

President Obama recently issued a warning to Democrats that the country’s deep polarization was making a close presidential election inevitable. (Pool photo by Anthony Behar /via European Pressphoto Agency )

In the past few days, Obama has issued stark warnings to Democrats that they could lose. According to several Obama aides and outside advisers, the change in tone is, in part, an inevitable product of the approaching election day. But it also is an acknowledgment of some of Clinton’s weaknesses.

White House officials have privately fretted about some of Clinton’s recent missteps, said supporters of the president who spoke on the condition of anonymity to discuss the issue frankly. Those mistakes and the narrowing polls have only intensified the president’s focus on the campaign, these officials said.

In remarks in recent days, Obama has cast the election as central to his legacy, essentially placing himself on the ballot with Clinton.

The president had begun drafting his recent remarks before his trip to Asia this month. Even before that trip, he had grown concerned that the historic unpopularity of the two candidates could depress turnout, a development that has traditionally favored Republicans. “It pisses him off when he hears people say, ‘I’m not going to vote. My vote doesn’t matter, they’re both lousy candidates,’ ” said a senior White House official who also spoke on the condition of anonymity.

Obama’s fiery speech Saturday to the Congressional Black Caucus Foundation was intended to energize African American voters. “There’s no such thing as a vote that doesn’t matter. It all matters,” Obama told the crowd. “You want to give me a good send-off? Go vote. And I’m going to be working as hard as I can these next seven weeks to make sure folks do.”

In a recent conference call with Clinton donors, former White House senior adviser David Plouffe told her supporters that it was imperative that Democrats win a decisive victory in November to prevent another politician like Trump from emerging on the national stage, according to one participant.

White House officials said it made sense that the president was making an explicit appeal to some of the groups most invested in his legacy, including African Americans.

Obama has been planning for weeks to make a series of appearances that are timed to maximize voter registration and turnout among African Americans and young people in key states. And he has been calling for greater civic involvement in the political process — by African Americans, in particular — going back to his speech last year marking the “Bloody Sunday” 50th anniversary in Selma, Ala.

“The president knows firsthand how important it is not to take a single vote for granted,” said White House deputy press secretary Eric Schultz. “And it is exactly the message he will be conveying for the weeks ahead to African Americans, young people, old people and anyone who needs an extra boost to remember what is at stake.”

Obama has framed the presidential race in increasingly personal terms, casting Trump as a repudiation of everything he has done over the past eight years. “Thanks, Obama,” the president quipped last week at a Philadelphia rally for Clinton after tallying his administration’s achievements.

But there are limits to what he can do for his former secretary of state. “He understands at the end of the day, Hillary Clinton is the one who has to give voters, and particularly the voters who elected him in 2008 and 2012, a reason to vote for” her, said one Obama confidant. “He knows he can’t deliver the election, and I don’t think the campaign is asking that. But he can help.”