The Senate confirmed President Trump's nominee to be Homeland Security secretary, Kirstjen Nielsen, by a narrow vote Dec. 5. (The Washington Post)

The Senate voted Tuesday to confirm Kirstjen M. Nielsen as the next secretary of the Department of Homeland Security, installing a close confidant of White House Chief of Staff John F. Kelly to lead the federal agency responsible for carrying out many of President Trump’s most ambitious domestic policy plans.

Nielsen, 45, developed a reputation for fierce devotion to Kelly as his deputy at the White House and before that as his chief of staff at the Department of Homeland Security, which he ran from January until July.

An attorney and cybersecurity expert, Nielsen will be the first DHS secretary with previous experience working at the agency. Her confirmation Tuesday gives the White House a DHS chief well versed in the politics and policy goals of Trump’s immigration enforcement agenda.

“By confirming Ms. Nielsen’s nomination to lead the DHS, this Senate will take a serious step to strengthen our nation’s security,” Senate Majority Leader Mitch McConnell (R-Ky.) said in a statement.

“Ms. Nielsen will be charged with leading the department at a critical time,” he said. “With her understanding of the challenges facing our nation and her experience in prevention and preparedness, I believe that she will excel as the next Secretary of Homeland Security.”

Tracking how many key positions Trump has filled so far

Nielsen was confirmed 62 to 37, the narrowest margin ever to approve a DHS secretary. Though no GOP senator voted against her, the outcome reflected intense opposition to Trump as well as doubts about Nielsen’s executive leadership experience and willingness to challenge the White House in the event of a disagreement.

Last month, a watchdog group filed an ethics complaint against Nielsen after she used a private consultant who represents clients with millions of dollars in DHS contracts to help her navigate the confirmation process.

In January, soon after Trump took office, senators confirmed Kelly 88 to 11.

Nielsen comes to the job largely on the power of Kelly’s endorsement. She will take over from acting secretary Elaine Duke, who filled the top job in a temporary capacity for more than four months, longer than any DHS chief in the agency’s 15-year history.

Duke was confirmed as deputy DHS secretary in April, but she does not have a close relationship to Nielsen. Several administration officials say Duke has informed the White House she plans to resign once Nielsen takes over. In a statement following Tuesday’s confirmation vote, Duke congratulated her and said “I look forward to working alongside Ms. Nielsen as her deputy.”

One of the Democrats who voted against Nielsen, Sen. Maggie Hassan (N.H.), said she had concerns about the new secretary’s independence. “Throughout her confirmation process, Ms. Nielsen failed to demonstrate that she would provide the steady experienced leadership — free from political interference from the White House — that the department needs.”

President Trump congratulates Kirstjen Nielsen, the newly confirmed Homeland Security secretary, during a White House ceremony in October to announce her nomination. (Jabin Botsford/The Washington Post)

Another Democrat who voted no, Sen. Kamala D. Harris (Calif.), cited similar doubts about Nielsen’s independence. She also criticized her reluctance during confirmation hearings to accept human behavior as a cause of global climate change and said Nielsen has “equivocated on protecting ‘dreamers,’ ” those brought to the country illegally as children and shielded from deportation under Obama.

As the top official leading the DHS, an agency with a $40 billion discretionary budget and 240,000 employees, Nielsen will take on a broad array of responsibilities. The DHS has 22 subagencies, including immigration enforcement, transportation security, disaster preparedness and response, the Secret Service, and the Coast Guard.

“There will be no on-the-job training for Kirstjen,” Trump said when he announced her nomination in October, praising her “sterling reputation.”

Nielsen has never held the top job at a federal agency or a private-sector company.

Early in her career, she worked at the Transportation Security Administration and then as a White House adviser for emergency preparedness and disaster management under President George W. Bush. During her confirmation hearing, she told senators she learned key lessons about emergency management by having a front-row seat to the botched response to Hurricane Katrina.

Nielsen breezed through her confirmation hearing last month before members of the Senate Committee on Homeland Security and Government Affairs, assuring lawmakers that she would not obey an unlawful order from the White House.

When asked for her views on the utility of a border wall with Mexico, she echoed comments made previously by Kelly that the United States did not need a 2,000-mile physical barrier “from sea to shining sea.”