Brett Kavanaugh has been sworn in as a US Supreme Court justice, just hours after the Senate backed President Donald Trump’s nominee 50 votes to 48.

Even as Mr Kavanaugh took his oath of office in a quiet private ceremony, not long after the narrowest Senate confirmation in nearly 150 years, protesters chanted outside the court building across the street from the Capitol.

Mr Kavanaugh had won confirmation after weathering sexual misconduct allegations and attacks on his character and temperament.

After weeks of intense debate that gripped the United States, the conservative appeals court judge had earlier won vows of support from two centrist senators, leaving no clear path in the Senate for Mr Kavanaugh’s opponents to block him.

Mr Trump celebrated the confirmation at a political rally in Kansas, condemning Democrats for what he called a “shameless campaign of political and personal destruction” against Mr Kavanaugh.

To cheers of supporters in Topeka, Mr Trump said “radical Democrats” had become “an angry, left-wing mob” and were “too dangerous and extreme to govern”.

Mr Kavanaugh, 53, was confirmed to the lifetime job during a historic roll call vote in the Senate chamber.

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

The vote unfolded with protesters in the gallery shouting, “I do not consent” as the roll call on Mr Kavanaugh began.

When senator Jeff Flake cast his vote in favour of Mr Kavanaugh, one protester shouted, “You’re a coward Flake, a total coward!”

Vice-President Mike Pence, who is presiding, repeatedly called for the Senate sergeant-at-arms to restore order in the chamber.

On Saturday morning (AEDT), Mr Kavanaugh just scraped through a procedural test when senators voted to advance his nomination to a final vote.

Capping a suspenseful day, Republican senator Susan Collins of Maine declared on the Senate floor, “I will vote to confirm Judge Kavanaugh”.

She praised his judicial record and argued there was no corroboration of sexual assault charges made against him by psychology professor Christine Blasey Ford.

Donald Trump says Ford named wrong person

Speaking to reporters onboard Air Force One after the confirmation, Mr Trump said he was “100 per cent” certain Dr Ford named the wrong person when she accused Mr Kavanaugh of assaulting her at a high school party in the 1980s.

“This is one of the reasons I chose him is because there is no one with a squeaky clean past like Brett Kavanaugh. He is an outstanding person and I’m very honoured to have chosen him,” Mr Trump said while flying to a campaign rally in Kansas.

“We’re very honoured that he was able to withstand this horrible, horrible attack by the Democrats.”

Two other women also accused Mr Kavanaugh of sexual misconduct decades ago. He has denied all the allegations.

Moments after Senator Collins pledged to back Mr Kavanaugh, Democratic Senator Joe Manchin, facing a tough race for re-election in West Virginia where Mr Trump is popular, also declared his support, paving the way for a Republican victory.

Senators then endured a rare all-night session to satisfy the requirement of 30 hours of debate following Friday’s vote.

Hundreds of protesters arrested

Amid tighter-than-usual security, thousands of protesters against Mr Kavanaugh assembled on the grounds of the Capitol and at the Supreme Court. Hundreds were arrested by police.

They chanted, “Vote them out! Vote them out!” and carried signs including “I am a survivor, not a troublemaker!”

Senate Republicans, except for Lisa Murkowski, stood by Mr Kavanaugh in a move that could resonate, particularly with female voters, in the November 6 congressional elections to determine control of the Senate and House of Representatives.

Even before the lurid sexual assault charges surfaced, Democrats in the Republican-controlled Senate were fighting hard to stop Mr Kavanaugh, saying his conservative judicial philosophy could result in rolling back abortion rights, gay rights and protections for immigrants.

Senate Majority Leader Mitch McConnell said the Senate “stood up for presumption of innocence” by confirming Mr Kavanaugh to the Supreme Court.

Senator McConnell said at a press conference that putting Mr Kavanaugh on the court “was about treating someone fairly”.

He called the vote “a good day for America” and predicted voters would reward Republicans for it in the midterm election.

A clear win for Donald Trump

Mr Kavanaugh’s confirmation gives Mr Trump a clear win in his drive to cement conservative dominance of the United States’ highest court, a bitter outcome for Democrats who could not get their own liberal nominee confirmed due to Republican delaying tactics in 2016.

His confirmation also allows Mr Trump to hit the campaign bragging that he has kept his 2016 promise to shape a more conservative American judiciary.

Ahead of the vote, Mr Trump told reporters that his nominee would “be a great Supreme Court justice for many years to come”.

Speaking in Cairo on the final leg of her visit to Africa, US first lady Melania Trump praised Mr Kavanaugh, saying he was highly qualified for the position.

“I’m glad that Dr Ford was heard. I’m glad that Judge Kavanaugh was heard, FBI investigation was done — is completed — and [the] Senate voted,” she said.

Ms Trump declined to say whether she believed Dr Ford.

Democrats also challenged the veracity of some of his Judiciary Committee testimony.

Senate Democratic Leader Chuck Schumer said Mr Kavanaugh represents “a hard-right, conservative jurisprudence, far, far away from what average Americans believe”.

Senator McConnell led the nominee’s defence, calling him “one of the most impressive, stunningly qualified nominees in our nation’s history” and accusing Democrats of a “smear” campaign.