Democrats confronted a political thunderclap Thursday following the Supreme Court’s ruling that partisan gerrymandering is beyond the reach of federal courts, sparking outrage among party leaders and giving new urgency to efforts to win back state legislatures next year.

The court’s 5-to-4 decision also electrified the 2020 presidential campaign, putting state-level power at the forefront of a Democratic primary season so far dominated by national issues.

Many Democratic presidential candidates argued that beating President Trump in 2020 is no longer enough, and they warned that Republicans could control the contours of electoral maps for generations unless the party finds a way to secure more state legislative majorities.

“Today, the Supreme Court refused to stop politicians rigging our democracy by writing election rules for their own benefit,” said former vice president Joe Biden. Sen. Elizabeth Warren (D-Mass.), another candidate, called the decision an “abomination.”

In an interview, Sen. Richard Blumenthal (D-Conn.) warned the decision could have far-reaching effects.

“The stakes are so much higher in the election of state legislatures because after 2020, [Republicans] can redraw the lines without any real constitutional strictures or guardrails,” he said. “The future of both congressional districts and state legislative lines will be decided for years to come. It’s hard to exaggerate how this is a crossroads election.”

The impact of the ruling was further highlighted by Justice Elena Kagan’s scathing dissent. “Of all times to abandon the Court’s duty to declare the law, this was not the one,” Kagan wrote. “The practices challenged in these cases imperil our system of government.”

Neal K. Katyal, who served as an acting solicitor general under President Barack Obama, called Kagan’s dissent “one for the ages.”

Democratic Party leaders offered one silver lining, however, saying they hoped to turn anger into action.

“Democrats are going to be very mobilized,” former South Carolina governor Jim Hodges (D) said in an interview. “You see that on the ground already in places like South Carolina,” an early-voting state in the presidential primary, “and in states where there isn’t an independent commission for redistricting, you’re going to see a push for that and fairness to the top of the agenda.”

Eric H. Holder Jr., the former attorney general who leads the National Democratic Redistricting Committee, told reporters Thursday that he and other Democratic leaders are already active on four fronts: litigation, reform efforts, electing candidates “who support fair maps” and grass-roots advocacy.

Holder told reporters that “the Roberts court” has “undermined” the nation. “We have a partisan majority that has done lasting damage,” he said.

But he also offered a note of hope.

“Just because the Supreme Court says the Republicans can gerrymander doesn’t mean the people of this country have to live with that decision,” Holder said, adding that Democrats’ biggest challenge will be “trying to break up” the gerrymandering put in place in 2011.

As of April 1, Republicans controlled both the governorship and the legislature in 22 states, compared with the Democrats’ full control in 14 states, according to the National Conference of State Legislatures.

Republicans are highly organized at the state level and have been successful at filling judiciary seats with conservatives during the Trump administration. Outside groups and donors are already committed to contesting the Democrats at every turn.

Writing for the majority, Roberts said that state courts could still play a role in partisan gerrymandering cases. But it will be hard for Democrats to mount successful challenges of gerrymandered maps through state courts. Thirty-eight states use elections as part of the process for choosing judges to serve on their high courts, according to data from the Brennan Center for Justice, which means challenging voting districts there can be difficult.

“This decision pulls the plug on all litigation in the federal courts challenging partisan gerrymandering,” said Richard Pildes, a law professor and redistricting expert at New York University.

And Republicans said they will not be complacent even as they celebrated the court’s decision. Former Wisconsin governor Scott Walker, an official with the National Republican Redistricting Trust, said Thursday that Republicans would “battle to protect our country from Barack Obama and Eric Holder’s plan to hijack our elections.”

“Democrats will double down on flipping state Supreme Courts and bring more lawsuits to be heard by friendly judges they helped to elect, just like they have already done in Pennsylvania and North Carolina and tried to do in Wisconsin,” Walker said.

Roberts’ decision does not foreclose the possibility for federal courts to intervene to address racial gerrymandering issues, or the “one person, one vote” principle that seeks to ensure that voting districts across states are roughly equal in population.

But African American leaders worry that partisan gerrymandering could erode the integrity of minority votes.

“Gerrymandering, voter I.D. laws, and voter roll purging are all racist tactics to suppress the votes of low income and black and brown people,” said Rev. Al Sharpton, the founder of the National Action Network, a nonprofit civil rights group.

Stacey Abrams, a former leader in Georgia’s state assembly and a national advocate on voting rights, tweeted that the Supreme Court “abdicated a fundamental obligation: to protect citizens” and effectively told voters that “their voices don’t matter.”

The Rev. William J. Barber II, a former president of the North Carolina NAACP, said in a text message that the decision is “a flexing of raw power by extremists. It is directed especially at the South,” and “5 justices are giving state legislatures a way to do racist voter suppression under the guise of partisan excuses,” he wrote.

Democrats in Congress attacked the ruling, while most Republicans remained mum. Many compared its lasting influence to the Supreme Court’s 2010 Citizens United decision, which struck down campaign spending limits on corporations.

Senate Minority Leader Charles E. Schumer (D-N.Y.) called Thursday’s decision “a devastating blow to our democracy”and predicted that “the American people, particularly communities of color, will greatly suffer because of it.”

House Speaker Nancy Pelosi (D-Calif.) said the court decision “strikes at the very heart of our American democracy.”

In a statement, Pelosi noted that the Democratic-led House has passed legislation that requires states to establish independent, nonpartisan redistricting commissions. Senate Majority Leader Mitch McConnell (R-Ky.) has said the legislation will not be considered by his chamber.

Democratic presidential candidates, ahead of the second round of the first Democratic debate, pledged to fight to overturn the ruling if they win the White House next year.

Warren said she would seek to require states to use independent redistricting commissions to draw political districts rather than leave that task to governors and state legislatures. Warren added that if Senate Republicans tried to block her legislation, she would seek to end the use of the filibuster in the chamber.

Doing so would allow legislation to pass with a simple majority rather than with the 60 senators currently required to cut off debate on most bills.

Sen. Kamala D. Harris (D-Calif.), another 2020 hopeful, said a ban on partisan gerrymandering would be a priority for her if elected.

“Politicians shouldn’t be able to pick their voters, voters should choose their representatives,” Harris said. “The Supreme Court’s gerrymandering decision will have drastic consequences for the future of our nation.”

Robert Barnes, Ann E. Marimow, Vanessa Williams, and Amber Phillips contributed to this report.