WASHINGTON — The Senate confirmed Rick Perry on Thursday as the head of the Energy Department, an agency he had once pledged as a presidential candidate to eliminate.

The vote was 62 to 37. Mr. Perry, a former Texas governor, will lead an agency that, despite its name, is largely focused on overseeing the nation’s vast arsenal of nuclear weapons, as well as a network of 17 national scientific laboratories.

In his confirmation hearing, Mr. Perry told senators that he regretted his call in the 2012 campaign to eliminate the agency. His inability to remember the name of the Energy Department in a 2011 debate, even as he called for getting rid of the agency, was widely seen as helping to sink his campaign.

People close to Mr. Perry said that at the time he had believed that the Energy Department was largely focused on developing and promoting the nation’s energy resources. At his January confirmation hearing, Mr. Perry told the Senate Energy and Natural Resources Committee that after “being briefed on so many of the vital functions of the Department of Energy,” he now supported its mission.