WASHINGTON — Judge Brett M. Kavanaugh was confirmed to the Supreme Court on Saturday by one of the slimmest margins in American history, locking in a solid conservative majority on the court and capping a rancorous battle that began as a debate over judicial ideology and concluded with a national reckoning over sexual misconduct.

As a chorus of women in the Senate’s public galleries repeatedly interrupted the proceedings with cries of “Shame!,” somber-looking senators voted 50 to 48 — almost entirely along party lines — to elevate Judge Kavanaugh. He was promptly sworn in by both Chief Justice John G. Roberts Jr. and the retired Justice Anthony M. Kennedy — the court’s longtime swing vote, whom he will replace — in a private ceremony.

For President Trump and Senate Republican leaders, who have made stocking the federal judiciary with conservative judges a signature issue, the Senate vote was a validation of a hard-edge strategy to stick with Judge Kavanaugh, even after his nomination was gravely imperiled by allegations by Christine Blasey Ford that he had tried to rape her when they were teenagers.

The president was exultant. “He’s going to go down as a totally brilliant Supreme Court justice for many years,” he told reporters, whom he had invited to join him in watching the vote on television aboard Air Force One.