Brett Kavanaugh has been sworn in as a US Supreme Court justice, hours after the Senate narrowly confirmed his appointment following a battle that rubbed raw the country’s cultural, gender and political divides.

The near party-line vote – a victory for Donald Trump – was 50-48, capping a fight that seized the national conversation after claims emerged that Mr Kavanaugh had sexually assaulted women three decades ago.

He emphatically denied the allegations, but they magnified the clash from a routine Supreme Court struggle over judicial ideology into an angrier, more complex jumble of questions about victims’ rights, the presumption of innocence and personal attacks on nominees.

Following the vote, Mr Kavanaugh was driven to the Supreme Court building across the street from the Capitol for a private swearing in ceremony.

The Senate roll call vote was interrupted several times by protesters in the galleries shouting “Shame on you”, before they were removed by police.

Protesters then moved to mass on the Supreme Court steps, chanting: “We believe survivors,” while some banged on the doors.

Mr Trump was flying to Kansas on Air Force One at the time of the vote, but was seen flashing a thumbs-up gesture when the result was announced. He praised Mr Kavanaugh for being “able to withstand this horrible, horrible attack by the Democrats”.

The vote gave Mr Trump his second appointee to the court, and comes in the amidst of campaigning for next month’s mid-term elections.

It was the closest roll call to confirm a justice since 1881, when Stanley Matthews was approved by 24-23, according to Senate records.

Within minutes, dozens of political and advocacy groups condemned the vote.

Stephanie Schriock, president of EMILY’s List, which contributes to female Democratic candidates, assailed the confirmation of “an alleged sexual assailant and anti-choice radical to a lifetime appointment on the Supreme Court”.

She added: “We will carry that anger into the election. Women will not forget this.”

Democratic leader Chuck Schumer also looked ahead to the mid-terms, and appealed to voters beyond the Senate chamber: “Change must come from where change in America always begins: the ballot box.”

Joe Manchin, facing a tough re-election race next month in a state that Mr Trump won in 2016 by a landslide, was the sole Democrat to vote for Mr Kavanaugh.

Every voting Republican backed the 53-year-old conservative judge.

Lisa Murkowski, the only Republican to oppose the nominee, voted “present”, offsetting the absence of Kavanaugh supporter Steve Daines.

The rare procedural manoeuvre left Mr Kavanaugh with the same two-vote margin he would have had if Ms Murkowski and Mr Daines had both voted.

Supreme Court Kavanaugh Protest FloridaProtesters had demanded the Senate rejected Brett Kavanaugh’s nomination (Jennifer Lett/AP)

When Mr Trump nominated Mr Kavanaugh in July, Democrats leapt to oppose him, saying that past statements and opinions show he could be a threat to court cases on the right to abortion.

They said he also seems too ready to rule for Mr Trump in a possible federal court case against the president.

Mr Kavanaugh replaces the retired Justice Anthony Kennedy, who was a swing vote on issues such as abortion, campaign finance and same-sex marriage.