(Reuters) - Republican Cindy Hyde-Smith won a U.S. Senate special election runoff in conservative Mississippi on Tuesday, defeating a black challenger after a campaign that recalled the history of racist violence in the deep South state.

Republican U.S. Senator Cindy Hyde-Smith speaks during an election night party in Jackson, Mississippi, U.S., November 27, 2018. REUTERS/Jonathan Bachman

The white former state lawmaker, who was appointed to the Senate in April, overcame a controversy over her comment on public hangings to defeat Democrat Mike Espy in the last contest of the 2018 election cycle.

Hyde-Smith, 59, is the first woman elected to Congress from Mississippi. If Espy had won, he would have been the first black senator from Mississippi since shortly after the Civil War.

Having been heavily favored to win the reliably Republican state, Hyde-Smith became engulfed in a political storm over a video showing her praising a supporter at a Nov. 2 event by saying, “If he invited me to a public hanging, I’d be on the front row.”

The video sparked a furor in a state with a history of racism and violence against blacks, including lynchings, and fueled Democratic hopes of an upset in a state where 38 percent of the population is black.

But Hyde-Smith triumphed by depicting Espy as too liberal for Mississippi, which last elected a Democrat to the Senate in 1982, and by touting her support for President Donald Trump, who won the state by 18 percentage points in 2016.

Trump attended two get-out-the-vote rallies in the state on Monday, and tweeted his congratulations to Hyde-Smith after the race was called, saying he was “very proud” of her.

Slideshow ( 17 images )

“Mr. President, thank you so much for all of your help,” Hyde-Smith said in a victory speech to supporters, calling her win a triumph of “conservative values.”

“Mississippians know me and they know my heart,” she said.

Her victory means Republicans will hold a 53-47 majority in the new U.S. Senate that convenes in January. With almost all precincts tallied, Hyde-Smith led by nearly 8 percentage points.

Espy, 64, campaigned as a moderate who would work with Trump and Republicans to benefit the state. He tried to recreate the coalition that propelled Democrat Doug Jones to a Senate win in neighboring Alabama last year by energizing black voters, particularly women, and winning support from white swing voters.

Espy said he called Hyde-Smith to concede the race and wish her well.

“She has my prayers as she goes to Washington to unite a very divided Mississippi,” he told supporters.

The runoff to serve the last two years of former Republican Senator Thad Cochran’s term was necessary because neither Espy nor Hyde-Smith gained more than 50 percent of the vote in a Nov. 6 special election with four candidates. Cochran, 80, resigned earlier this year, citing health concerns.

Several businesses, including giant retailer Walmart, had demanded Hyde-Smith return their donations after her public hanging remark.

She sparked further controversy when she was shown on another video joking about suppressing liberal student votes, and photographs surfaced of her posing with Confederate artifacts in 2014.

She initially refused to apologize for the hanging remark, but said in a debate last week that she was sorry “for anyone that was offended.” She accused Espy of twisting her words for political gain.

Espy denied the charge and said “we all know what came out of your mouth.” He has said the comment perpetuated negative stereotypes about Mississippi and hurt investment.