Democratic Senate candidate Kyrsten Sinema captured a long-held Republican seat in Arizona, defeating Republican Martha McSally and narrowing the GOP’s majority in the upper chamber.

Sinema, a three-term congresswoman, overcame attacks on her more liberal record as an Arizona state legislator and committed to a bipartisan approach in a race that hinged on issues such as health care and illegal immigration. Her defeat of McSally will make her the first female senator in Arizona’s history.

Nearly a week after Election Day, the Associated Press projected Sinema as the winner on Monday. She had 49.7 percent of the vote to McSally’s 48 percent after mail-in and absentee ballots were counted. Of the more than 2.2 million ballots cast, Sinema won by 38,197 votes.

She will replace Sen. Jeff Flake (R-Ariz.), who has tangled with President Trump and often criticizes the president’s harsh rhetoric. Last week, Trump mocked Flake and boasted about retiring him, telling reporters at a post-election news conference, “I’m very proud of it; I did the country a great service.”

It has been 30 years since Democrats held a Senate seat in Arizona. In remarks after she was projected the winner, Sinema said her victory was a rejection of “name-calling” and “petty personal attacks,” and she paid tribute to a Republican, the late senator John McCain (R-Ariz.), who died of cancer in August.

McCain was “irreplaceable but his example will guide our next steps forward. He always put country ahead of party,” Sinema said.

Flake, on Twitter, congratulated Sinema “on a race well run, and won. It’s been a wonderful honor representing Arizona in the Senate. You’ll be great.”

McSally tweeted her congratulations and said: “I wish her success. I’m grateful to all those who supported me in this journey. I’m inspired by Arizonans’ spirit and our state’s best days are ahead of us.”

It was unclear what will happen to the state’s other Senate seat, which is held by Republican Jon Kyl. Kyl was appointed to replace McCain and has not committed to serving past this year.

It is possible that Republican Gov. Doug Ducey would appoint McSally to the seat.

Sinema’s win was a major boost for Democrats, who entered the election cycle defending more seats than the GOP and scrambled to save 10 incumbents in states Trump won.

In the West, Democrats flipped a seat in Nevada as Rep. Jacky Rosen ousted GOP Sen. Dean Heller, and prevailed in Arizona, where Trump won in 2016.

Republicans hold a narrow majority of 51 to 47, with two other Senate races still unresolved on Monday: the close contest in Florida between Republican Gov. Rick Scott and Democratic Sen. Bill Nelson and a runoff scheduled for Nov. 27 in Mississippi pitting appointed Sen. Cindy Hyde-Smith, a Republican, against Mike Espy, a Democrat.

McSally lost the race after abandoning the moderate profile she had nurtured in her 2014 congressional race and allying herself with Trump. The former Air Force combat pilot adopted an aggressive tone, accusing Sinema of supporting treason over her 2003 remark that it was “fine” if a radio host who was asking her a question joined the Taliban.