Justice Anthony M. Kennedy seemed to hold the key in two redistricting cases Monday where the justices were considering whether Republicans had unconstitutionally packed minority voters together to limit their influence.

His comments should cause concern for Virginia lawmakers, who lost at the court last term for the way they drew congressional districts and this time were defending a dozen legislative seats from challenges by African American voters.

[Supreme Court leaves in place decision on Virginia gerrymandering]

“I have problems” with the way the lower court analyzed and approved the districts, Kennedy told Paul D. Clement, the lawyer representing Virginia.

In both cases argued Monday — the other involves two congressional districts in North Carolina — the court was considering whether race played too large a role in drawing districts. States and municipalities say they face pressure under the Voting Rights Act to draw districts that give minorities a shot at electing the candidates of their choice.

But the Supreme Court for decades has held that race cannot be the predominant factor in drawing electoral lines.

That can be a difficult balance to find, and Justice Samuel A. Alito Jr. complained that the issue was “very, very complicated” and that any decision by the state seems to serve only as “an invitation for litigation.”

At issue in Virginia are 12 House districts in Richmond, the Hampton Roads area and along the state’s southern border. All were held by African American representatives.

Republicans who drew the new map after the 2010 Census said their goal was to preserve those incumbents. To do that, Republicans said each of the districts would have a black voting age population of 55 percent.

But African Americans and Democrats complained that the real intent was to pack black voters into those districts so the surrounding districts would be more winnable for Republicans.

A panel of three federal judges upheld the districts last year.

But Marc E. Elias, the lawyer representing the challengers, said that the judges were wrong to rule that race did not play the predominant role in drawing lines.

“Virginia applied this 55 percent rule to move voters in and move voters out of districts on the basis of race, regardless of the differences in voting patterns, geography, demographics or the actual interests of black voters in each of those districts,” he said.

Chief Justice John G. Roberts Jr. said it was difficult for the court to discern what motivation was the dominant one when lawmakers were drawing the map. And partisan gerrymandering, as opposed to racial decisions, is allowed under the court’s current jurisprudence.

But Justice Elena Kagan suggested that there must be a more detailed approach than the one Virginia employed.

“It sort of defies belief you could pick a number and say that applies with respect to every majority-minority district,” she said.

But Clement said the number was not picked “from thin air.” Some of the majority-minority districts that the state wanted to protect already had black voting age populations larger than that.

“The 2011 redistricting of the Virginia House of Delegates was a bipartisan success story,” Clement said, noting that the changes were endorsed by the legislature’s black caucus.

Even though Virginia has elected two Democrats to the U.S. Senate and voted for the Democratic presidential candidate in the past three elections, it is much more divided at the state level. Republicans hold 66 seats in the 100-member House. As the result of the congressional map approved by the court last term, the commonwealth elected a second African American congressman. Republicans will hold seven of 11 seats.

In the North Carolina case, a lower court had rejected how the state legislature drew two congressional districts. The arguments were similar to those in the Virginia case — and the lawyers were identical.

Clement said those arguing that the drawing of one district was racially motivated, rather than partisan, should be required to produce an alternative map.

But Kagan questioned that, and Elias agreed that there “are all manner of ways to prove that race predominated.”

A separate three-judge panel has struck down some of North Carolina’s legislative districts and said there must be new elections in 2017. That decision is probably headed to the Supreme Court as well.

Justice Stephen G. Breyer noted that he had written several of the court’s rulings on reapportionment and had tried in a 2015 decision to give guidance to lower courts that would alleviate the need for the justices to step in so frequently.

“It certainly doesn’t seem to have done” that, Breyer said.

The cases are Bethune-Hill v. Virginia State Board of Elections and McCrory v. Harris.