WASHINGTON — Two of President Donald Trump’s former rivals for the GOP White House nomination won Senate confirmation Thursday to join his administration.

Retired neurosurgeon Ben Carson was confirmed as secretary of the Department of House and Urban Development on a vote of 58-41. A few hours later, the Senate backed former Texas Gov. Rick Perry to be energy secretary, 62-37.

Carson and Perry are the 17th and 18th of Trump’s 22 Cabinet and Cabinet-level nominations to win Senate approval.

Carson has never held public office and has no housing policy experience. Republicans have praised the life story of a man who grew up in inner-city Detroit with a single mother who had a third-grade education.

Perry, who once pledged to eliminate the department, has repeatedly promised be an advocate for the agency and to protect the nation’s nuclear stockpile. Perry also pledged to rely on federal scientists, including those who work on climate change.

Perry, who served 14 years at Texas governor, has said he will seek to develop American energy in all forms, from oil, gas and nuclear power to renewable sources such as wind and solar power.

Democrats say they accept Perry’s disavowal of his 2011 pledge to abolish the department, but they worry he may not stand up to GOP proposals to slash the department’s budget.

Carson, 65, will lead an agency with some 8,300 employees and a budget of about $47 billion. The department provides billions of dollars in housing assistance to low-income people through vouchers and public housing. It also enforces fair housing laws and offers mortgage insurance to poorer Americans through the Federal Housing Administration, part of HUD.

Trump lauded Carson last week, calling him a “totally brilliant neurosurgeon” who has saved many lives.

“Ben is going to work with me very, very closely. And HUD has a meaning far beyond housing. If properly done, it’s a meaning that’s as big as anything there is, and Ben will be able to find that true meaning and the true meaning of HUD as its Secretary,” Trump said.

Carson has not shared specific plans publicly for the department under his leadership.

At his confirmation hearing, he told lawmakers that he envisioned forging a more “holistic approach” to helping people and developing “the whole person.” He didn’t offer many details.

Perry, 66, told a Senate committee that he regrets his infamous statement about abolishing the department and insisted it performs critical functions, particularly in protecting and modernizing the nation’s nuclear stockpile.

During Perry’s tenure as governor, Texas maintained its traditional role as a top driller for oil and natural gas, while also emerging as the leading producer of wind power in the United States and a top provider of solar power.

Under questioning from Democrats, Carson said HUD’s rental assistance is “essential” to millions of Americans and that the department has a lot of good programs. But he added, “We don’t want it to be way of life. … We want it to be a Band-Aid and a springboard to move forward.”

He also said he’d like to see more partnerships with the private sector and religious groups.

The soft-spoken Carson, the only black major-party candidate in the White House race, grew up poor. He went on to attend Yale University and the University of Michigan Medical School before becoming the first African-American named as the head of pediatric neurosurgery at Johns Hopkins Children’s Center in Baltimore.

In 1987, Carson became famous for pioneering surgery to separate twins joined at the back of the head. In 2013, he entered the national political spotlight during the National Prayer Breakfast when he railed against the modern welfare state, with President Barack Obama sitting just feet away.

GOP Sen. Lisa Murkowski of Alaska, who leads the Senate Energy and Natural Resources Committee, said Perry was a strong leader with a record of getting results.

Democrats and environmental groups have derided Perry’s nomination, calling him a steep drop-off from the two renowned physicists who preceded him as energy chief, Steven Chu and Ernest Moniz.

Perry earned a bachelor’s degree in animal science from Texas A&M University, where he was also a member of the Corps of Cadets and a Yell Leader.