The Senate voted to confirm Judge Brett M. Kavanaugh as the Supreme Court’s 114th justice on Saturday by one of the narrowest margins in the institution’s history.

The 50-to-48 vote capped off a brutal confirmation fight that underscored how deeply polarized the nation has become under President Trump.

Trump nominated Kavanaugh in July to succeed retired justice Anthony M. Kennedy, a move that triggered an intense partisan battle over the court’s future well before allegations of decades-old sexual misconduct against Kavanaugh surfaced, delaying a confirmation vote by a week to allow for a limited FBI investigation.

Before the vote, Senate Minority Leader Charles E. Schumer (D-N.Y.) warned that his colleagues were “about to elevate a nominee who doesn’t belong on the nation’s highest bench.”

Schumer suggested several reasons, including Kavanaugh’s temperament at a high-profile hearing last week at which faced off with his initial accuser, Christine Blasey Ford, and exchanged sharp words with several Democrats on the Judiciary Committee.

“To Americans, to so many millions who are outraged by what happened here, there’s one answer: Vote,” Schumer said.

The acrimonious battle over Kavanaugh’s confirmation is certain to influence next month’s midterms, pitting energized female voters angered by the treatment of Kavanaugh’s accusers against conservatives who see him as a man wrongly accused.

In an interview with The Post, Senate Majority Leader Mitch McConnell (R-Ky.) called the opposition to Kavanaugh and the protests a “great political gift” to the GOP ahead of the elections, where control of both the House and Senate are on the line.

Saturday’s vote broke largely along party lines, with one Democrat, Sen. Joe Manchin III of West Virginia, supporting Kavanaugh, and one Republican, Sen. Lisa Murkowski of Alaska, opposing his nomination.

The margin was the narrowest for a confirmed Supreme Court justice since 1881, when the Senate confirmed Stanley Matthews, a nominee of President James A. Garfield.

Trump said the confirmation process was “really unattractive” but said the weeklong delay for an FBI investigation turned out to be “very positive.”

“He’s going in looking very good,” Trump said of Kavanaugh.

Kavanaugh’s fate remained unclear until Friday, when three Republicans and one Democrat became the last to announce how they would vote.

Sen. Patty Murray (D-Wash.) said that by confirming Kavanaugh, the Senate would be sending a deeply troubling message both to the nation’s girls and women — “your experiences don’t matter” — but also to its boys and men.

“They can grab women without their consent and brag about it,” Murray said. “They can sexually assault women, laugh about it. And they’re probably going to be fine. They can even grow up to be president of the United States or a justice on the Supreme Court.”

As the vote drew nearer Saturday afternoon, hundreds of protesters arrived outside the Capitol, with dozens sitting on the building’s center steps. Dozens were arrested, raising their fists as police escorted them away, and some broke through police barricades.

There were chants of “the whole world is watching” and “vote them out” and signs that included “Kava Nope” and “We’ll remember in November.”

Many were standing outside the Capitol in handcuffs as the confirmation vote was taken.

Ford, Kavanaugh’s initial accuser, alleged that he sexually assaulted her at a high school gathering in suburban Maryland in the early 1980s. Two other women came forward to accuse Kavanaugh of misconduct while in high school and college.

Following a hearing that included testimony from both Ford and Kavanaugh, the confirmation vote was delayed a week to allow the FBI to conduct a limited investigation into the allegations of Ford and a second accuser, Deborah Ramirez, who alleged Kavanaugh exposed himself while in college. Republicans said the FBI report showed no corroboration of the allegations and exonerated Kavanaugh, while Democrats argued it was too limited in scope to be enlightening.

Several Republicans who spoke on the Senate floor Saturday argued that the allegations against Kavanaugh simply didn’t hold up.

“We do not want a system of guilty until proven innocent in America,” he said.

In a new statement on a GoFundMe page, Ford said she believed and still believes “that it was my civic duty to come forward, but this is by far the hardest thing I’ve ever had to do, much harder even than I thought it would be.”

On Saturday, Ramirez issued a statement saying that witnesses who could have corroborated her allegations were not interviewed by the FBI.

“Thirty-five years ago, the other students in the room chose to laugh and look the other way as sexual violence was perpetrated on me by Brett Kavanaugh,” she said. “As I watch many of the Senators speak and vote on the floor of the Senate I feel like I’m right back at Yale where half the room is laughing and looking the other way. Only this time, instead of drunk college kids, it is US Senators who are deliberately ignoring his behavior.”

During remarks before Saturday’s vote, Sen. John Cornyn (R-Tex.), the No. 3 Republican in the chamber, defended the way the Senate had treated Ford.

“We treated her the same way we would want our wives or daughters to be treated,” he said.

Mike DeBonis, Paul Kane and Gabriel Pogrund and Carol Leonnig in Washington and Ezra Austin in Princeton, N.J., contributed to this report.

‘It has affected my mental health’: George Mason students protest Brett Kavanaugh teaching a summer law course

Survivors of sexual assault have mobilized to demand that he be terminated

Before Ruth Bader Ginsburg, there was Sandra Day O’Connor. The first female Supreme Court justice was an ‘unfeminist feminist.’

A new biography reveals how O’Connor, a moderate Republican, didn’t always vote the way people expected her to