The Senate voted to confirm former Raytheon Co. executive Mark Esper as U.S. defense secretary, ending the longest period in Pentagon history without a congressionally approved leader.

Mr. Esper was confirmed by a bipartisan tally of 90 to 8, with all of the “no” votes coming from Democrats. None of the six senators running for the 2020 Democratic presidential nomination supported Mr. Esper, with five voting against the nominee, and one, Sen. Bernie Sanders (I., Vt.), not voting.

Supreme Court Justice Samuel Alito swore in Mr. Esper during a ceremony Tuesday night in the Oval Office.

“I’m confident that he will be an outstanding Secretary of Defense,” Mr. Trump said during the ceremony. The president also touted the Senate’s 90-8 vote to confirm Mr. Esper. “That’s a vote we’re not accustomed to,” he said.

Mr. Esper takes the place of former defense chief Jim Mattis, who resigned in December over disagreements with the Trump administration about U.S. policy on Syria, personnel decisions and other issues.