(Reuters) - Republican U.S. Representative Martha McSally’s embrace of President Donald Trump and his agenda paid off on Tuesday, when the Arizonan beat back conservative challengers for her party’s nomination in a crucial U.S. Senate race.

But Republican strategists warned that her shift to the right on Trump and his hard-line immigration policies could also prove an albatross in November, when she will face a well-funded moderate Democratic congresswoman, Kyrsten Sinema, in a race expected to be tight.

The primary highlighted the delicate dance for many Republicans running in tough elections this year, given Trump’s sky-high approval ratings among voters of his own party: criticizing Trump too harshly risks losing the Republican base, while embracing him too warmly could alienate moderate voters who disapprove of his performance.

The race has also put into stark relief how thoroughly Trump now dominates his party.

“It did put McSally in a precarious position,” said Mike Noble, an Arizona-based Republican pollster. “But what’s the point if you don’t win the primary?”

Democrats need to capture two seats from Republicans to take control of the Senate in the Nov. 6 congressional elections and halt Trump’s legislative agenda.

Most analysts believe the party must win in Arizona to have any chance at doing so. The state voted for Trump by 3.5 percentage points in 2016, but Democrats are buoyed both by its rapidly diversifying electorate and by a national political environment favoring their candidates.

“Independent, unaffiliated voters have a generally negative view of the president, and that’s the audience McSally is going to have to appeal to,” said Paul Bentz, a veteran Arizona Republican political consultant not involved in the campaign.

The seat is held by retiring Republican Senator Jeff Flake, perhaps the most vocal Trump critic among congressional Republicans.

Slideshow ( 9 images )

Trump held off on endorsing anyone in the primary race until Wednesday morning, when he announced his support for McSally on Twitter.

“Martha McSally is an extraordinary woman,” Trump wrote. “... Has my total and complete Endorsement!”

McSally, 52, who built a reputation as a moderate Republican after winning a competitive congressional race in 2014, had the Republican establishment’s backing in the nominating race. Senate Majority Leader Mitch McConnell warned that the Tucson woman represented the party’s only chance of keeping control of the seat.

She faced two challengers from the right in the primary: former Maricopa County Sheriff Joe Arpaio, 86, and former state Senator Kelli Ward, 49.

IMMIGRATION A KEY ISSUE

Immigration, Trump’s signature issue, has long been the top concern among Republican voters in the Southwestern state bordering Mexico, according to pollsters; both Arpaio and Ward are immigration hawks with ties to the president.

Arpaio, one of Trump’s staunchest supporters, received a presidential pardon after he was convicted of contempt for refusing to obey a court order to stop racially profiling Latinos. Trump has also praised Ward.

Their presence in the race forced McSally, who previously criticized Trump on occasion and has refused to say whether she voted for him in 2016, to position herself as a defender of Trump’s agenda.

Slideshow ( 9 images )

Earlier this year, she removed her name from a bill she had co-sponsored that offered a path to citizenship for so-called “Dreamers,” young illegal immigrants who arrived in the United States as children. She has expressed support for Trump’s proposed U.S.-Mexico border wall.

In interviews, McSally has denied changing her positions. Her campaign did not respond to questions from Reuters about her rightward turn.

Democrats have signaled they will attack her on those grounds, adopting the mocking nickname “Martha McShifty.”

“As a GOP primary candidate, Congresswoman McSally morphed herself into a Trump Republican who refuses to stand up to her party’s leaders,” the state Democratic Party said in a campaign memo released on Tuesday.

Sinema, a former Green Party member, has undergone her own political shift toward the middle over the years, joining the “Blue Dog Coalition” of moderate Democrats after winning her seat in 2012 and voting against Democrat Nancy Pelosi’s re-election as minority leader in 2016.

The website VoteView, which estimates how liberal or conservative members of Congress are based on their legislative voting history, lists Sinema as the second-most conservative Democrat in the House, behind only the newly elected Conor Lamb of Pennsylvania.

With only token opposition in her primary, Sinema, a 42-year-old Tucson native, has been free to run essentially a general election campaign for months, positioning herself as an independent voice and eschewing attacks on Trump by name.

In an advertisement last week, McSally previewed one likely line of attack, noting her background as the first female Air Force fighter pilot to fly in combat during the Iraq War while criticizing Sinema for protesting that war in 2003.

“This is how I see this campaign. It’s a choice between a doer and a talker ... between a patriot and a protestor,” McSally wrote on Twitter after her win Tuesday night.