As Donald Trump and Hillary Clinton begin to tighten their grips on their respective party nominations, President Obama is plunging into the campaign fray, not only to help Democrats retain the White House but also in defense of his own legacy in a political climate dominated by Trump.

“The president has been clear that as we get closer to the general election, it will become even more important that the American people understand what is at stake,” White House deputy press secretary Jennifer Friedman said in an email.

Obama and his top aides have been strategizing for weeks about how they can reprise his successful 2008 and 2012 approaches to help elect a Democrat to replace him. And out of concern that a Republican president in 2017 — either Trump or Sen. Ted Cruz (Tex.) — would weaken or reverse some of his landmark policies, Obama and his surrogates have started making the case that it is essential for the GOP to be defeated in November.

As a result, Obama is poised to be the most active sitting president on the campaign trail in decades.

“Do we continue to build on the policies that reward hard-working American families . . . and address challenges for future generations, or do we stop in our tracks, reverse our progress and move in the wrong direction?” Friedman wrote. “This is a choice that the president does not take lightly, and is something he will lay out for the American people with increased frequency in the weeks and months ahead.”

Central to the White House effort to stop Trump — or, under a less likely scenario, one of his rivals — is reassembling and energizing the coalition that propelled Obama into office; that means African Americans, Latinos, young voters and women.

Speaking at a Democratic National Committee fundraiser in Austin last Friday, Obama said consolidating the gains that Democrats have made over the course of his presidency will depend on ensuring that people are “engaged and working just as hard and just as full of hope as they did in 2008.”

One big worry for Democrats is the level of enthusiasm among the party’s base when Obama is no longer on the ballot.

“There’s a tendency, in the third election in a row for a party, for there to be some sense of complacency,” said former White House senior adviser Dan Pfeiffer. What Democrats need to do in the coming months is clear, he said: “The difference between Donald Trump winning or losing is whether Obama’s 2008 coalition turns out in 2016.”

Many Democrats think that if Trump is the GOP nominee, he will help the Democratic Party solve the mobilization problem. They think that Trump’s strident anti-immigrant positions and his controversial comments about women and minorities will help Democrats in the fall.

Latino voters, especially, are receiving the attention of advocacy groups, including super PACs friendly to the Clinton campaign and to Democrats in general.

Liberal investor George Soros is among the backers helping to amass about $15 million for a super PAC devoted to increasing the participation of Latino voters as well as African Americans and women.

Vice President Biden, for his part, is preparing to campaign heavily in the Rust Belt to appeal to the white, working-class voters who may be drawn to Trump, according to aides.

Democratic Party officials say they are taking the threat of a Trump nomination seriously and plan to begin attacking him immediately, on policy and on his temperament. They also vow not to make the mistakes that Trump’s GOP opponents made early in the primary season. They are not assuming that the billionaire real estate magnate will self-destruct, they say.

“We’re ready for Donald Trump,” DNC Chair Debbie Wasserman Schultz told reporters Wednesday. “We’re not treating him like the laughingstock that Republican establishment folks treated him for far too long.”

Obama in recent days has been in the forefront of those viewing Trump as a serious electoral threat. More than once, the president has gone on extended riffs about why he thinks Trump as a political leader is bad for the country.

“The best leaders, the leaders who are worthy of our votes, remind us that even in a country as big and diverse and inclusive as ours, what we’ve got in common is far more important than what divides any of us,” he said in Dallas last Saturday, just as reports about violence at Trump rallies were dominating the news.

Increasingly, Obama has been using Trump’s candidacy to talk about what kind of country the United States is becoming. At a St. Patrick’s Day luncheon at the Capitol on Tuesday, Obama again alluded to Trump’s harsh campaign rhetoric.

“In America, there aren’t laws that say that we have to be nice to each other, or courteous, or treat each other with respect. But there are norms. There are customs,” he said. “The longer that we allow the political rhetoric of late to continue, and the longer that we tacitly accept it, we create a permission structure that allows the animosity in one corner of our politics to infect our broader society. And animosity breeds animosity.”

Clearly, once there is a Democratic nominee — who Obama advisers say they expect will be Clinton — the president will hit the campaign trail on that nominee’s behalf.

Obama and Biden recently endorsed two Democrats involved in contested Senate primaries, former Ohio governor Ted Strickland and U.S. Rep. Patrick Murphy (Fla.), and on Thursday they endorsed former senator Russell Feingold (D-Wis.) in his bid to retake his seat.

Republican national spokeswoman Lindsay Walters said in an email that Obama will be “a huge liability” in swing states because he has “job approval numbers that continue to struggle.”

“An overwhelming majority of the people want a different approach than Obama,” Walters wrote. “Polls show Americans are tired of the status quo and want to take our country in a new direction.”

Democrats, by contrast, think the key to winning this year is, in the words of one party strategist, “more about mobilizing your own voters than persuading some rapidly shrinking middle.”

In the latest Washington Post-ABC News poll, Obama had an overall approval rating of 51 percent, but his approval was 87 percent among Democrats, 67 percent among voters under 30 and 75 percent among Hispanics. He regularly polls at 90 percent among African Americans.

Scott Clement, Anne Gearan and Abby Phillip contributed to this report.

“The difference between Donald Trump winning or losing is whether Obama’s 2008 coalition turns out in 2016.”

Dan Pfeiffer, former White House senior adviser