John McCain's death means potential legal battle to fill his Senate seat

The longtime senator died Saturday at the age of 81.

The timing of McCain’s death results in a complicated process that could end up in a court battle in a state that will be key to determining the balance of power in the U.S. Senate this midterm cycle.

According to Arizona state law, the governor appoints a replacement for any vacancy in a U.S. Senate seat who will hold it until the "next eligible general election."

That person must belong to the same political party of the person who held the seat.

That means Doug Ducey, Arizona's Republican governor, would appoint a Republican to fill McCain's seat until the next general election or until the governor decided to call a special election.

However, the most relevant piece of election code in this situation is that the candidate filing deadline for the election cannot be fewer than 90 days before a primary for that special election.

The State of Arizona Election Procedures Manual stipulates that the vacancy "must occur sufficiently before" that deadline to gather signatures to get on the primary ballot.

Since the Arizona primaries will be held this Tuesday, the filing deadline for candidates would have had to have been May 30 for a special election to comply with state law.

So even though the next general election in Arizona is in November, the timing of McCain’s passing likely ensures that whomever Ducey appoints to replace him will serve until 2020, the next general election year.

Matt Roberts, the communications director for the Arizona Secretary of State, confirmed to ABC News that under state election regulations, Ducey can appoint a replacement that will serve in McCain’s seat until 2020.

Democrats could challenge that relevant portion of state election guidance to try and force a special election in 2018, which would put both of the state's Senate seats up this cycle since retiring Sen. Jeff Flake's seat is also up.

When asked about potential plans to pursue legal action to force a special election in 2018, a spokesperson for the Arizona Democratic Party declined to comment on the subject, instead telling ABC News, "John McCain is an American hero and our thoughts are with him and his family at this difficult time."

A special election this year would force Republicans to defend two Senate seats this cycle in a state Donald Trump won by just four percentage points in the 2016 presidential election.