Democrat Kyrsten Sinema won Arizona's open Senate seat in a race that was among the most closely watched in the nation.

Sinema defeated Republican Rep. Martha McSally in the battle to replace GOP Sen. Jeff Flake.

The three-term congresswoman won after a slow vote count that dragged on for nearly a week after voters went to the polls on November 6.

Sinema will be Arizona's first Democratic US senator since 1994.

PHOENIX (AP) — Democrat Kyrsten Sinema won Arizona's open U.S. Senate seat Monday in a race that was among the most closely watched in the nation, beating Republican Rep. Martha McSally in the battle to replace GOP Sen. Jeff Flake.

The three-term congresswoman won after a slow vote count that dragged on for nearly a week after voters went to the polls on Nov. 6. She becomes Arizona's first Democratic U.S. senator since 1994. Her win cemented Arizona as a swing state after years of Republican dominance.

Sinema portrayed herself as a moderate who works across the aisle to get things done.

McSally, a former Air Force pilot who embraced President Donald Trump after opposing him during the 2016 elections, had claimed that Sinema's anti-war protests 15 years ago disqualified her and said one protest amounted to what she called "treason."

But during her six years in Congress, Sinema built one of most centrist records in the Democratic caucus, and she voted for bills backed by Trump more than 60 percent of the time. She backed legislation increasing penalties against people in the country illegally who commit crimes.

McSally's attacks on Sinema reached back more than 15 years, when Sinema was a Green Party spokeswoman and liberal activist.

McSally backed Trump's tax cut, border security and the Affordable Care Act repeal agenda as she survived a three-way GOP primary in August, defeating two conservative challengers who claimed her support for Trump was fake. McSally also campaigned on her military record and support for the Armed Forces.

Rep. Martha McSally. Nicole Neri/Reuters

Sinema attacked McSally's leadership of last year's failed Affordable Care Act repeal effort as a sign that she would not protect Arizona residents with preexisting medical conditions. McSally argued that she would protect patients, despite her vote on the bill that would have removed many of those protections.

The contest drew more than $90 million in spending, including more than $58 million by outside groups, according to Federal Election Commission reports. Attack ads by both sides clogged the airwaves for months.

Sinema, 42, has a law degree, worked as a social worker and was a political activist in her 20s, running as an independent Green Party candidate for the Arizona House. She then became a Democrat and served several terms in the state Legislature. Sinema started as an overt liberal but developed a reputation for compromise among her Republican peers, laying the groundwork to tack to the center.

When the 9th Congressional District was created after the 2010 Census, Sinema ran for the Phoenix-area seat as a centrist and won the 2012 election.

McSally, 52, was the first female Air Force pilot to fly in combat, flying A-10 attack jets. She also was the first woman to command a fighter squadron, again in A-10s.

McSally lost her first race in Arizona's 2nd congressional district in 2012, when she was narrowly defeated by Democratic Rep. Ron Barber, who replaced Rep. Gabby Giffords after she was wounded in a 2011 assassination attempt. But McSally came back to win the 2014 election, beating Barber by a narrow margin. She was re-elected in 2016.

Flake was an outspoken critic of Trump and announced in 2017 that he would not seek re-election, acknowledging he could not win a GOP primary in the current political climate. His support of the president's initiatives, however, was mixed. He strongly backed last year's tax cut bill but criticized Trump's positions on free trade.