WASHINGTON — The Senate on Monday confirmed President Obama’s nominee for surgeon general, ending a long fight over gun control and politics that had left the country without a permanent top doctor for a year and a half.

In an early-evening vote, Dr. Vivek H. Murthy, an internal medicine physician, was approved, 51- to 43.

The confirmation was one of the last acts of business for the Democratic-controlled Senate. Had it not moved, the nomination would have died, making it unlikely the president would have been able to get anyone approved to the post for the remainder of his time in the White House.

Democrats said there was no compelling reason to delay the Murthy nomination, especially as the nation’s public health system remains on edge after the Ebola outbreak in West Africa and a number of recent scares at American hospitals. In a statement applauding the vote, Mr. Obama directly cited the threat from Ebola and said that Dr. Murthy’s confirmation would help make the country safer.