WASHINGTON—The Senate on Tuesday confirmed Chuck Hagel as the nation's next defense secretary largely along party lines, after several Republicans earlier in the day ended their effort to stop a vote on the former senator.

The 58-41 vote brings to a close a contentious battle that some experts believe could leave Mr. Hagel in a weaker position to take up the mantle at a challenging time for the Pentagon, which faces a series of deep budget cuts.