WASHINGTON — A crop of legal challenges to contorted legislative districts in states like Marylandwill soon give the Supreme Court its best opportunity in years to consider whether mapsdrawn for partisan advantage deprivevoters of an equal voice in elections.

Good-government groups believe the justices are poised to take up redistricting cases from North Carolina or Wisconsin — or both — in the next term. The plaintiffs are challenging the legality of one party drawing an electoral map that all but guarantees its candidates will win nearly all the seats.

Either case could have implications for Maryland, where squirrelly congressional lines have helped Democrats control seven of the state's eight House seats, but have drawn criticism from analysts, voters and the high court itself. The late Justice Antonin Scalia described Maryland's congressional map as a “crazy quilt” in a redistricting case last year.

“We think there are five justices interested in devising a legal standard to stop partisan gerrymandering,” said Gerry Hebert, executive director of the Campaign Legal Center, a public interest group that advocates for voting rights and fair elections.

Hebert said rigged districts are “a significant reason for the hyper-partisanship and political gridlock we currently see in state and federal politics.”

Repeatedly in past decades, the Supreme Court has said it is troubled by partisan gerrymandering, but stopped short of finding a plan unconstitutional. Many of those cases have originated in states controlled by Republicans, but the situation in Maryland shows that Democrats also routinely face criticism for drawing partisan boundaries.

A unanimous court sided with a Bethesda man last year by allowing his challenge to Maryland's congressional districts to proceed in a lower court.

Stephen M. Shapiro, a law student and former federal employee, argued that voters' First Amendment rights were trampled when lawmakers in Annapolis drew the current boundaries in 2011. The case is now pending before a three-judge panel in federal district court.

All three claims — in North Carolina, Wisconsin and Maryland — hang on language in past opinions that suggest the justices might be open to considering the constitutionality of boundaries drawn for political purposes.

Justice Anthony Kennedy cast the fifth vote in 2004 to reject a gerrymandering claim from Pennsylvania, but said a state would cross the line if one party admitted it had drawn the districts to deny the other party's “right to fair and effective representation.”

Kennedy also warned of the “threat” posed by computer programs that make it easier for lawmakers to draw district lines to rig outcomes. If the courts don't intervene, he wrote then, “the temptation to use partisan favoritism in districting in an unconstitutional manner will grow.”

In the North Carolina case, lawyers say they have the evidence Kennedy is looking for.

The state is a battleground in presidential politics: It alternated between Republican and Democratic candidates in 2004, 2008 and 2012, and polls show the pattern continuing this year, with Democrat Hillary Clinton leading Republican Donald Trump. But there's no question who will win most of the state's 13 House districts in November.

“It's virtually certain that Republicans will hold their 10-to-3 advantage, regardless of what happens in the presidential race,” said David Wasserman, an analyst with Cook Political Report. “The districts are simply far too polarized.”

When GOP lawmakers redrew the congressional map in 2011, they moved more black voters into two districts that had elected black Democrats, leaving Republicans with safe majorities in 10 of the 13 districts.

In February, a three-judge panel called the plan a “racial gerrymander” and ordered changes.

Republican leaders met in Raleigh to quickly redraw the lines, this time saying they would not use race, but instead, party affiliation. The result was the same 10-3 advantage — and they acknowledged their aim was to lock that in.

“We want to make clear,” said state Rep. David Lewis, that “we are going to use political data … to gain a partisan advantage on the map” and maintain “our partisan advantage.”

There is “nothing wrong with political gerrymandering. … It is not illegal,” added state Sen. Bob Rucho.

Lawyers for the North Carolina Democrats seized on those comments in an appeal to the Supreme Court. They have urged the justices to render a decision on the constitutionality of partisan gerrymandering this fall.

Common Cause North Carolina has filed a separate suit asking a three-judge panel to strike down the state's map.

“If there was ever a time for the courts to take a look at this, this is it,” said Bob Phillips, the group's executive director. “This is a competitive state, where [President Barack] Obama won narrowly in 2008, and [Mitt] Romney won narrowly in 2012. But the congressional delegation does not reflect that.”

Lewis and Rucho, the authors of the redistricting plan, criticized the lawsuit as “just the latest in a long line of attempts by far-left groups to use the federal court system to take away the rights of North Carolina voters.”

In 2012, 51 percent of North Carolina voters cast House ballots for a Democrat, yet Republicans won nine of the 13 seats to Congress. One Democratic incumbent narrowly won in a Republican-leaning district, but stepped aside in 2014, when it became clear that he would not win re-election.

North Carolina provides an extreme example, but it follows it the national trend. Competitive House races are rare, since districts in most states are drawn to favor Republicans or Democrats. In 2014, the average margin of victory for a House candidate was 35.8 percent, according to Ballotpedia, a nonpartisan almanac of election data.

Pennsylvania, which has voted Democratic in national elections but has a Republican-controlled Legislature, regularly sends 13 Republicans and five Democrats to the House. Ohio, another toss-up state, sends 12 Republicans and four Democrats.

Virginia, which voted for Obama and has two Democratic senators and a Democratic governor, has been sending eight Republicans and three Democrats to Congress. On the other side of the Potomac River, Maryland's Democratic-controlled General Assembly drew districts that gave Democrats seven of eight seats in the House.

Maryland's congressional map, crafted after the 2010 census by then-Gov. Martin O'Malley and Democrats in the General Assembly, drew criticism when it was unveiled. The contorted House districts, which bound together dissimilar communities, helped Democrats oust longtime Republican Rep. Roscoe G. Bartlett in the 2012 election.

Though the maps were affirmed by voters in a 2012 referendum, they remain a point of political contention and repeated litigation. Republican Gov. Larry Hogan has proposed an independent commission to set district lines in the future.

Hogan would be in a position to insist on change if he is re-elected in 2018. His second term would include the next redistricting, scheduled for 2021.

Analysts say the North Carolina and Wisconsin cases could have a significant impact in Maryland, depending on how the court handles them.

“When it comes to partisan gerrymandering, the courts have allowed the parties to engage, essentially, in a back-alley brawl — no rules, no referees and no holds barred,” said KathayFeng, national redistricting director at Common Cause. “What we're seeing, we think, in the last term is that the court is indicating that it's interested in stepping into the referee role.”

The Wisconsin case focuses on the state legislature and the electoral map drawn when Republicans took full control in 2011.

A year later, 51 percent of the voters cast ballots for Democrats, yet Republicans still won a supermajority of 60 of 99 seats in the StateAssembly, Wisconsin's lower chamber.

“Wisconsin has the most extreme partisan map in the United States,” saidHebert of the Campaign Legal Center.

In May, a three-judge panel heard arguments on whether the plan is unconstitutional, and a ruling is expected soon. If the judges uphold the plan, the challengers say they will file an appeal directly to the Supreme Court.

Unlike other federal cases, election and voting cases are heard by three-judge panels, and their rulings go directly to the Supreme Court, where the justices are required to either affirm or reverse the decision.

The problem of gerrymandering has a very long history. In 1812, a Boston newspaper drew a cartoon that depicted a salamander-shaped district that favored the candidate of Gov. Elbridge Gerry, and thereafter such odd-looking districts were dubbed “gerry-manders.”

But nowcomputers can use granular voter information to draw adistrict map with neat lines that nonetheless effectively assures one party will win a supermajority of seats in Congress or the state house for the next decade.

Baltimore Sun reporter John Fritze contributed to this article.