Republican Rep. Martha Roby campaigns in Andalusia, Ala., on May 30. (Mickey Welsh/AP)

Rep. Martha Roby (R-Ala.), who once turned away from President Trump, won political renewal with his support on Tuesday, emerging victorious from a runoff that served as a referendum on her allegiance to the president.

Roby, who condemned Trump in 2016, defeated a primary challenger who aggressively highlighted her past. The challenger, former congressman Bobby Bright, faced attacks about his history as a onetime Democrat who supported Nancy Pelosi for speaker.

At her victory celebration, Roby thanked Trump and Vice President Pence for their endorsements, and she called for a more civil political discourse.

“I will always strive to approach campaigns and fierce political debates with civility in mind,” Roby said. “Our words have consequences, and as leaders, we have a responsibility to use them wisely.”

Roby defeated Bright by a margin of more than 2 to 1.

In an early morning tweet Wednesday, Trump congratulated Roby, noting that he had endorsed her late in the race and saying she “had the kind of landslide victory that you deserve.”

Tuesday’s runoff, which was triggered when Roby failed to win a majority of the vote on June 5, was the latest test of proximity to Trump, who remains widely popular among conservative voters despite losing ground among independents and Democrats.

Roby avoided becoming the third Republican House member to lose in a primary this year. The most recent victim, Rep. Mark Sanford of South Carolina, had a well-documented history of anti-Trump commentary.

Across the country, Trump’s dominance continues to be evident in Republican primaries, with scores of candidates adopting his positions and political tactics, ever wary of appearing hostile to him. Those who have shunned him in the past have raced to make up for it.

Roby is one of them. She won just 39 percent of the vote in this year’s primary. The main reason: She had criticized Trump in the 2016 campaign, after the release of a videotape that caught him bragging about groping women.

Roby urged Trump to “step aside and allow a responsible, respectable Republican to lead the ticket.” That fall, she won reelection — but ran 17 points behind the president in her southeastern Alabama district. Nearly 30,000 conservatives wrote in other names to protest her Trump statement, and many Republicans mobilized against her.

Earlier this year, Bright, who held the 2nd Congressional District seat before losing it to Roby in 2010, joined the primary, which featured three other challengers who branded Roby as disloyal to the president.

But unlike most other past Trump critics, Roby won the most powerful tool for squashing skepticism about her loyalty to Trump: a runoff endorsement from the president himself.

In a June 22 tweet, Trump wrote that Roby had become “a consistent and reliable vote for our Make America Great Again Agenda.” Top Republicans amplified his message.

House Majority Leader Kevin McCarthy (R-Calif.) encouraged Trump to make the endorsement, according to two Republicans familiar with the situation who described the private outreach on the condition of anonymity.

A recorded phone message went out to voters this week featuring Pence. In television ads, the U.S. Chamber of Commerce portrayed Roby as a key Trump ally and Bright as a Democratic turncoat.

Roby emphasized her support for Trump’s proposed border wall in the campaign and has largely supported his agenda on Capitol Hill. She also sought to tie Bright to Pelosi, the House minority leader and former speaker, and cast herself as a staunch opponent of the California Democrat.

Roby also ran on the clout she had built across four terms in a Republican majority, from backing work requirements for food-stamp recipients to barring money for Planned Parenthood.

Bright, meanwhile, focused on Roby’s 2016 comments about Trump and her voting record to argue that she had lost her way. A former mayor of Montgomery who had been one of the House’s most conservative Democrats, Bright said he wanted to shut down the special counsel’s probe into Russian interference in the 2016 election.

Bright contended that his move into the Republican Party was not a problem for voters. He aligned himself with Trump, though he said the president’s endorsement of Roby didn’t mean she would win.

But Trump’s support has proved to be a valuable asset in Republican primaries this year. After Rep. Daniel Donovan (R-N.Y.) won Trump’s endorsement, he ran 28 points ahead of challenger Michael Grimm, who was hobbled by a criminal conviction.

In South Carolina, the president made a last-minute endorsement of state legislator Katie Arrington, hours before she defeated Sanford.

Elsewhere, Republicans who have been hostile to Trump in the past have made an effort to move closer to him. Rep. Martha McSally, who is vying for the Senate nomination in Arizona, has shifted to the right on immigration and says she has a “great relationship with the president.” McSally once said she was “appalled” by the videotape that was released in 2016.

In Mississippi, insurgent conservative Senate hopeful Chris McDaniel, who supported Sen. Ted Cruz (R-Tex.) against Trump in the 2016 presidential race, is playing up support for the president. He recently announced he had parted ways with a campaign strategist because the aide was too critical of Trump.

While the first round of the primary revealed Roby’s vulnerability, most Republicans expected her to defeat Bright heading into Tuesday’s vote. Alabama Democrats also expected Bright to lose, citing Republican discomfort not just with his term in Congress but also with his roots in Montgomery, which is seen in the “Wiregrass” region that makes up most of the district as a bastion of crime and liberalism.

Republicans in Alabama were also picking nominees in three statewide races Tuesday. Attorney General Steve Marshall held off conservative challenger Troy King, while state legislator Will Ainsworth defeated Public Service Commission President Twinkle Cavanaugh in the lieutenant governor’s race. Small-town mayor Rick Pate defeated Gerald Dial, a state legislator, in the race for agriculture commissioner.

All three winning Republicans are favored to win in November, as is Roby. Tabitha Isner, the business analyst who won the Democratic nomination in the 2nd Congressional District, has raised less than $250,000 for her campaign and has been left off her party’s target lists.

Trump won the 2nd District by about 32 points in 2016.

Erica Werner contributed to this report.