Arizona Gov. Doug Ducey on Tuesday appointed fellow Republican Rep. Martha McSally to the Senate, picking a favorite of GOP leaders to fill the seat John McCain held for decades despite some misgivings about the congresswoman.

McSally, who lost a close race for Arizona’s other Senate seat this year, will succeed Sen. Jon Kyl (R), who will step down at the end of the year. After McCain’s death in August, Kyl returned to the Senate to fill his seat temporarily.

McSally is expected to run for the seat in a 2020 special election, setting the stage for a potential marquee contest in a battleground state. The seat also will be on the ballot in 2022.

“Martha McSally is uniquely qualified to fight for Arizona’s interests in the United States Senate,” Ducey said at a news conference with McSally in Phoenix. The two shook hands, then briefly hugged.

McSally’s appointment came after a period of frustration for Ducey and his closest confidants, who were disappointed with her campaign and the way her team handled the aftermath of the election.

McSally also needed to mend her frayed relations with McCain’s family. The congresswoman distanced herself from the senator this year, while aligning with Trump. That didn’t sit well with McCain’s widow, Cindy McCain, an emerging political power broker in the state. McSally apologized to her last week in a meeting Ducey encouraged.

Moving forward, McSally faces a challenging balancing act in a demographically changing state where the opposing forces of Trump and the McCain family both wield influence. She experienced the consequences of snubbing McCain; but there is also risk in straying too far from Trump, who has helped defeat Republicans who defy him and probably will be on the ballot in 2020.

McSally told Ducey she was “humbled by the confidence you’ve placed in me.” She said she looked forward to working with Sen.-elect Kyrsten Sinema (D), who defeated her in this year’s contentious and competitive campaign. McSally said she texted Sinema on Tuesday.

“There’s a lot of common ground between us, and I’m ready to hit it running,” said McSally.

Ducey said Sinema will be sworn in first and will be the state’s senior senator. The governor said he wanted to “respect the will of the voters.”

McSally will become the 25th woman serving in the Senate at the start of the 116th Congress that begins in January, a record high. Arizona will be one of six states with all-women Senate delegations.

Ducey’s decision comes after weeks of tension with McSally and her political strategists. Last week, Ducey and his close confidants were frustrated with McSally — to the point that the governor’s interest in appointing her had diminished, according to two people familiar with this thinking who spoke on the condition of anonymity to freely discuss private conversations.

But McSally remained a finalist, and in recent days she has tried to improve her standing with Ducey and the other Republicans she clashed with during her campaign.

A onetime Trump critic, McSally reinvented herself as a staunch supporter of the president during her Senate campaign. She largely avoided mentioning John McCain, who had traded public criticism with the president.

On Friday, McSally apologized to Cindy McCain for her lack of praise for the senator on a defense bill named in his honor, according to two people familiar with the conversation and who spoke on the condition of anonymity to describe a private discussion.

McSally’s posture for much of the campaign also bothered other McCain friends and family members. Cindy McCain emphasized the importance of respecting the legacy of the seat during her meeting with McSally, according to the people familiar with their conversation.

The governor said Tuesday that he was glad McSally and Cindy McCain could meet and “clear the air.”

In a tweet Tuesday, McCain wrote: “My husband’s greatest legacy was placing service to AZ & USA ahead of his own self-interest. I respect @dougducey’s decision to appoint @RepMcSally to fill the remainder of his term. Arizonans will be pulling for her, hoping that she will follow his example of selfless leadership.”

McSally praised John McCain strongly Tuesday, calling him a “giant in the Senate, an Arizona icon and an American hero.” She said she would commit to hold herself “to the standard of service that Senator McCain exemplified: putting country before self and always striving to do the right thing for Arizonans.”

A memo McSally’s campaign strategists issued after the election was also a source of friction. Ducey and his confidants were angry with the document, which blamed her loss on external factors rather than reflecting on strategic decisions they made.

In the end, however, Ducey concluded that McSally would give the party the best chance of holding onto the seat in two years. Senate Majority Leader Mitch McConnell (R-Ky.) has long seen McSally as the best bet to keep the seat in GOP hands and has advocated for her behind the scenes.

McSally brings an established fundraising network, relationships with Republican officials and name recognition, thanks to the many advertisements she ran during this year’s campaign.

Democratic strategists have mentioned several potential candidates in their party who may run for the seat in 2020. They include Mark Kelly, a former astronaut and the husband of former congresswoman Gabrielle Giffords (D).

Grant Woods, a former chief of staff to McCain who also was state attorney general, has said he has taken steps toward running as a Democrat. Rep. Ruben Gallego, a liberal Democrat, also has been mentioned as a prospective candidate.

The Democratic Senatorial Campaign Committee went after McSally on Tuesday. “Why appoint a loser when you could find a fresh face with a better shot in 2020?” DSCC communications director Lauren Passalacqua said in a statement.

Ducey wrestled with his decision in part over his desire to ensure that a strong Republican candidate would be on the ballot in 2020. The governor believes that election could be more difficult for Arizona Republicans than this year’s vote, according to the people familiar with his thinking.

After McSally’s loss and the way she handled it, Ducey was not immediately convinced that she could fill that role. He also considered appointing his former chief of staff, Kirk Adams.

McSally is a former Air Force pilot who was the first woman to fly in combat. She was first elected to the House in 2014. McSally has emphasized her military background on the campaign trail, and Ducey praised her service Tuesday.

Republicans will hold 53 Senate seats in the new Congress. The Democratic Caucus will have 47 members.