Republican Cindy Hyde-Smith has won Mississippi’s racially charged Senate election, beating a challenge from the black Democrat, Mike Espy.
It extends the Senate majority of President Donald Trump’s party 53 for Republicans and 47 for Democrats.
The race narrowed after Ms Hyde-Smith, who is white, was recorded saying she would happily attend a public hanging.
The comments evoked the lynching of African-Americans in a state scarred by a history of racial violence.
With nearly all votes counted, Ms Hyde-Smith had taken 53.9% of the vote in the staunchly Republican state compared to 46.1% for Mr Espy.
This victory has made her the first ever US congresswoman to be elected from Mississippi.
President Trump tweeted his congratulations.
In a statement, Ms Hyde-Smith said: “I want everybody to know, no matter who you voted for today, I am going to represent every Mississippian.”
Conceding to his opponent, Mr Espy tweeted that he was “proud of the historic campaign we ran and grateful for the support”.
The run-off election campaign had dredged up aspects of the Deep South state’s ugly past.
On Monday, several nooses were found at the Mississippi capitol in Jackson in an apparent protest against the tenor of the campaign.
Signs alongside the ropes urged voters to elect “someone who respects the lives of lynch victims” and “remind people that times haven’t changed”, according to local media.
This election became more competitive after a video emerged earlier this month of Ms Hyde-Smith – who is the incumbent senator – saying she would be “on the front row” if one of her supporters “invited me to a public hanging”.
For many, the comment evoked past lynchings of African-Americans.
Comments became a rallying call
Analysis by Chris Buckler, BBC News, Mississippi
Many said this was Cindy Hyde-Smyth’s election to lose – and some will argue she seemed to try pretty hard.
Joking about a public hanging in a state with a history of racially-motivated lynchings wasn’t just insensitive – it was a rallying call for opponents.
A number of businesses even asked her for their donations to be returned.
Eventually there was an apology but by then the comments had come to overshadow Senator Hyde-Smith’s campaign and everywhere she faced questions about racial division rather than the election race.
Despite everything she can console herself in the knowledge that this was a decisive win.
President Trump, who congratulated her on the result, will also be patting himself on the back. He undoubtedly helped to motivate his supporters with appearances in Mississippi at eve-of-election rallies.
Yet Democrats and their candidate Mike Espy may well claim some sort of moral victory. In a state widely regarded as a Republican stronghold they made this run-off election a genuine battle.
In his statement admitting defeat, Mr Espy pointedly wrote that Mississippi’s future would be brighter than its past.
According to the National Association for the Advancement of Colored People (NAACP), Mississippi had the highest number of lynchings in the nation from 1882 to 1968.
Mr Espy condemned his rival’s comment as “reprehensible”; Ms Hyde-Smith maintained there was no “negative connotation”.
The Democrat has himself come under scrutiny for his 2011 lobbying work in the Ivory Coast, whose former despot Laurent Gbagbo is on trial at the International Criminal Court.
Mr Espy was agriculture secretary under President Bill Clinton, but resigned under a cloud of corruption allegations, on which he was later acquitted.
Ms Hyde-Smith, meanwhile, was further criticised when photos surfaced of her posing at the home of Confederate President Jefferson Davis, with the caption: “Mississippi history at its best.”
A video of Ms Hyde-Smith apparently encouraging voter suppression also emerged on Twitter.
That recording showed the senator saying there were some liberals “who maybe we don’t want to vote – maybe we want to make it just a little more difficult [to vote]”.
Her campaign later said the comment was a joke and the video had been “selectively altered”, the Washington Post reported.
At a recent debate, Ms Hyde-Smith gave a qualified apology to anyone she had offended, while adding that opponents had “twisted” her words “as a political weapon”.
President Donald Trump travelled to Mississippi on the eve of the vote to campaign for Ms Hyde-Smith.
“I know her, and I know she apologised, and she misspoke,” the Republican president told reporters on his way to the state.
He painted Mr Espy as a far-left ideologue who would “rather protect illegal aliens than people who live in Mississippi”, and questioned how he “fit in with Mississippi”.
Had he won, Mr Espy would have become the first black senator for Mississippi since the Reconstruction era following the US Civil War.
Mr Espy’s campaign had pushed the idea that electing Ms Hyde-Smith would stoke a lingering view of Mississippi as a racist southern state.
“We can’t afford a senator who embarrasses us and reinforces the stereotypes we’ve worked so hard to overcome,” one ad for the Democrat said.
Mr Espy needed to overwhelmingly win the black vote and a substantial number of white voters to unseat his Republican opponent.
Why was the election still unresolved?
After Republican Senator Thad Cochran resigned in April, a special election for Mississippi’s US Senate seat was arranged.
Under the state’s law, if no candidate wins over 50% of the votes, a runoff election must take place.
On 6 November during the mid-term elections, both Ms Hyde-Smith and Mr Espy received about 41% of the vote.