WASHINGTON — The Senate voted on Tuesday to confirm Kirstjen Nielsen as the secretary of homeland security, elevating a top White House aide and former agency official to oversee the department central to President Trump’s plan to crack down on illegal immigration and beef up border security.

The vote was 62 to 37.

Ms. Nielsen will replace John F. Kelly, who left in July to become the White House chief of staff. Ms. Nielsen served as Mr. Kelly’s chief of staff at the Homeland Security Department, and he brought her along to the White House to be his deputy.

Elaine C. Duke, a deputy Homeland Security secretary, has served as the acting secretary in the interim. Ms. Duke has said she would remain at the department in the No. 2 position, tamping down speculation that she might resign after Ms. Nielsen was installed.

Ms. Nielsen has faced questions about her lack of experience running a large organization — Homeland Security is the third-largest department in the federal government — but has defended herself as up to the task. A former Transportation Security Administration official, she will be the first former employee to lead the department.