WASHINGTON — A deeply divided Senate voted on Tuesday to confirm Republican Chuck Hagel to be the nation’s next defense secretary, handing President Barack Obama’s pick the top Pentagon job just days before billions of dollars in automatic, across-the-board budget cuts hit the military.

The vote was 58-41, with four Republicans joining the Democrats in backing the contentious choice. Hagel’s only GOP support came from former colleagues Thad Cochran of Mississippi, Dick Shelby of Alabama and Mike Johanns of Nebraska — all three had announced their support earlier — and Rand Paul of Kentucky.

The vote came just hours after Republicans dropped their unprecedented delay of a Pentagon choice and allowed the nomination to move forward on a 71-27 vote.

Hagel, 66, a former two-term Nebraska senator and twice-wounded Vietnam combat veteran, succeeds Defense Secretary Leon Panetta. Hagel is expected to be sworn in at the Pentagon on Wednesday.

Obama welcomed the bipartisan Senate vote, although 41 Republicans opposed his nominee, and said in a statement that “we will have the defense secretary our nation needs and the leader our troops deserve.”