President Obama is endorsing U.S. Senate candidate Katie McGinty, D-Pa., who was campaigning in April at a SEPTA subway stop in west Philadelphia. (Bill Clark/CQ-Roll Call,Inc.)

Barack Obama rose to prominence as a different kind of Democrat, an outsider who was not part of the establishment and who would chart a separate course. Eight years later, the president finds himself working hard to restore a party from which he was once eager to stand apart.

Obama has presided over a greater loss of electoral power for his party than any two-term president since World War II. And 2016 represents one last opportunity for him to reverse that trend.

But it is also a challenge for the president who has experimented with establishing his own political base outside the Democratic National Committee and has downsized the scale of political operations inside the White House.

The first big tests of the rebuilding efforts come Tuesday in Pennsylvania, where Obama is taking the unusual step of wading into two contested Democratic primaries, endorsing Senate hopeful Katie McGinty and Josh Shapiro, a Montgomery County official and early supporter of his who is hoping to become state attorney general.

See how the opposing party has gained ground under every president since Truman

Should Democrats claim those two offices in the fall, it would represent a small dent in what has become a worrisome decline of power for the party below the presidential level under Obama’s watch.

Between 2008 and 2015, Democrats lost 13 Senate seats, 69 House seats, 913 state legislative seats, 11 governorships and 32 state legislative chambers, according to data compiled by University of Virginia professor Larry J. Sabato. The only president in the past 75 years who comes close is Dwight D. Eisenhower, who saw a similar decline for the GOP during his time in office.

“The Republican Party is arguably stronger now than they’ve ever been in 80 years, despite not having the White House,” said Simon Rosenberg, a longtime Democratic operative and president of NDN, a liberal think tank.

Democrats also are concerned about whether the coalition Obama galvanized in 2008, and then reassembled in 2012, will turn out when he is no longer on the ballot. The current Democratic presidential primary contest has so far fractured that coalition, with young people flocking to Sen. Bernie Sanders of Vermont while many voters of color — especially older ones — back former secretary of state Hillary Clinton.

Many factors have contributed to Republicans’ gains on the state and federal levels, including a concerted push by their donors to target state races and a midterm election that allowed them to lock in favorable congressional district lines.

Obama’s defenders contend that after major victories in 2006 and 2008, it was predictable that Democrats would lose significant ground in the midterm elections of 2010 and 2014. But, they add, the president’s two successful White House bids have vastly upgraded the party’s voter outreach infrastructure by expanding the national voter file the Democratic National Committee first started in 2006. And they point to the huge increases in the number of Democratic campaign volunteers — from roughly 252,000 in 2004 to 2.2 million in 2012 — as evidence of that upgrade.

“Barack Obama has single-handedly modernized the Democrats’ ability to wage campaigns on the local level,” said Jim Messina, who managed Obama’s re­election campaign.

Rosenberg agrees, saying that the president built on the work of Bill Clinton, the only other two-term Democratic president of the last generation. “Clinton established the intellectual framework for the Democratic Party and Obama modernized its politics,” Rosenberg said. “What isn’t there yet is a large enough set of leaders from the next generation to carry it on.”

Some of Obama’s earliest decisions continue to reverberate negatively for Democrats.

Organizing for Action (OFA), the nonprofit group that grew out of Obama’s campaign operation, has continued to compete with the Democratic National Committee for Democratic dollars — first as a parallel organization within the DNC and then as a separate entity. In the first six months of 2013, the DNC raised $30.8 million, while OFA raised $13 million. And this was at a time when the DNC was carrying more than $18 million in debt.

Those fiscal constraints meant the DNC had to curtail the money it provided to state parties, a practice that DNC chair Debbie Wasserman Schultz (D-Fla.) reversed in 2015 by increasing the monthly minimum transfer to each state from $5,000 a month to $7,500.

Close cooperation has taken time; OFA gave the DNC limited access to its list of supporters starting in 2013, but it turned over the entire list only in August 2015. Now, according to Nevada Democratic Party chair Roberta Lange, “That voter file is used by everyone in our state.”

While many OFA volunteers have focused on local referendums and other local political battles, the group has earned the enmity of some party stalwarts for diverting resources. During a 2010 gathering of Democratic governors in Washington, according to multiple attendees, one governor asked a senior presidential political adviser, “Will the OFA please join the Democratic Party?”

But this White House, unlike that of Bill Clinton, has always kept its political operation on a separate track.

Under Clinton, the political affairs office boasted roughly a dozen people — in addition to the deputy chief of staff who oversaw political affairs — and the president got a political briefing once a week.

By contrast, Obama limited election activity in the White House, a reflection of both his desire to keep any scandal at bay and the influence of White House chief of staff Denis McDonough, who has little campaign experience outside of working on Obama’s first presidential bid.

Obama phased out the political affairs office after two years to move the operation to his Chicago campaign headquarters. He appointed David Simas, who directs the White House Office of Political Strategy and Outreach, to his current position only in January 2014, after congressional Democrats complained they did not have a direct White House contact for political matters.

Obama’s senior political advisers from his first term — Messina, David Plouffe and David Axelrod, among others — have left to focus on ventures in the private sector and academia and scaled back their involvement in day-to-day Democratic politics.

Plouffe said it was natural for veteran strategists to move on but acknowledged that Obama’s relationship with his top political operatives didn’t automatically translate to other candidates. “You don’t do your best work being a mercenary,” said Plouffe, now a strategic adviser to the car service firm Uber.

He added that it will take the commitment of wealthy Democratic donors — not just top party officials — to target state contests the way Republicans have. “I think we all agree something has to be done,” he said. “The question is how. It’s not going to be the DNC.”

Obama, for his part, has set limits for what he will do in connection with super PACs while in office. While he did fundraising events for the one that backed his reelection campaign, Priorities USA, McDonough and Obama’s lawyers curtailed what the president would do two years later for the Senate Majority PAC, a similar entity supporting Senate Democrats.

In an April 2014 memo to then-Senate Majority Leader Harry M. Reid (D-Nev.), the PAC’s counsel, Marc E. Elias, stipulated that to avoid any conflict of interest Obama would not actually ask potential Senate Majority PAC donors for money even when appearing at one of the group’s events. After making this point on the memo’s first page, he reiterated two pages later, with underlined emphasis: “Again, to be clear: the President will not solicit contributions at or in connection with any of these meetings.”

After a protracted and bitter exchange, Reid’s aides abandoned their effort to involve Obama in any more than a few super PAC events, and the president agreed to transfer $5 million from the DNC to both the Democratic Senatorial Campaign Committee and the Democratic Congressional Campaign Committee in the fall of 2014. During the 2012 cycle, the DNC made no transfers to the two committees.

But with his popularity high among Democrats and no election ahead of him, Obama has been working to shore up his party, both financially and politically. And his aides say Obama has turned controversial issues, including immigration, gay rights and climate change, to the Democrats’ advantage.

“He will be aggressive, from the presidential level down to the state and local representative level,” Simas said. “There’s going to be a Democratic nominee and Democratic candidates. They are the ones who are going to be driving the campaigns, and the president will be there to be as helpful as possible.”

Recently in Dallas, before dozens of guests who had each given thousands of dollars to the Democratic Senatorial Campaign Committee, Obama diagnosed one of the problems: “Democrats just aren’t very good at focusing on down-ballot races,” he said, according to two participants.

The president may have been stating the obvious. But it reflected a shift in thinking among Democrats, who are working furiously to shore up state-level candidates to avoid getting beaten once again on redistricting. Since 2013, Obama has devoted considerable time to fundraising for the DNC and both congressional committees, doing more than 100 events for the DNC alone.

Sen. Charles E. Schumer (N.Y.), the second-ranking Democrat in the Senate, said that when he asked Obama to make a series of primary endorsements this cycle, including one of McGinty, “He just did it with no muss, no fuss, in a very great way.”

In December, the heads of three party committees met to develop a joint redistricting strategy, and Obama signed a redistricting fundraising appeal for the Democratic Governors Association in January. Even former members such as Rep. Barney Frank (D-Mass.) have been asked to attend fundraisers on behalf of state lawmakers in states such as Ohio.

“We have to be better and smarter about playing that long game and making those investments,” said Rep. Steve Israel (D-N.Y.), adding that while House Democrats will have “a very strong wind at their backs” this year, “The day after this election, we have to understand that the wind’s going to be in our faces.”

In 2014, many Democrats in conservative states were eager to tap Obama’s fundraising prowess but were reluctant to appear side-by-side with a president with sagging popularity ratings. Already, 2016 is different.

Longtime Democratic strategist Donna Brazile said that for a long time Democrats wanted Obama’s resources — including money and analytics — “but they didn’t want his presence.” When she called the White House last year to ask if the president would do robo-calls to African American voters during Louisiana’s special election for governor, White House officials seemed surprised that Democrat John Bel Edwards even wanted their help. Brazile assured them that he did.

And Democrats increasingly believe that they will need Obama in the fall to regain some of the ground they’ve lost since 2008.

“Part of his legacy is to rebuild the bench,” Brazile said.

Democratic Congressional Campaign Committee Chairman Ben Ray Luján (N.M.) said in an interview that the president will help in unifying the Democratic base.

“He’s going to help boost turnout in November, which is critical when you’re winning races on the margins,” Luján said.