The Senate on Thursday confirmed Gina Haspel as CIA director, making her the first woman to lead the spy agency despite the controversy surrounding her role in the waterboarding program.

The Senate vote of 54-45 in favor of Haspel came mostly, but not entirely, along party lines. She needed support from several Democratic senators to win confirmation.

Her confirmation effectively completes President Trump's recent shakeup of his national security and foreign policy teams.

In recent weeks, John Bolton has become the national security adviser, Mike Pompeo has become secretary of state, and Haspel takes over for Pompeo at the CIA.

In addition to being the CIA's first female director, Haspel is also the first career CIA officer to lead the agency since William Colby in the 1970s.

Haspel, 61, is widely respected in the intelligence community. Since joining the CIA in 1985, just a few years out of college, she has held some 20 separate jobs at the agency, including seven postings abroad.

The CIA says those foreign postings were in Europe, Eurasia and Africa, though it has declined to name the countries, saying that's classified information.

Haspel was undercover for her first 32 years at the agency, a status lifted just last year when she became deputy director to Pompeo.

Trump then picked Pompeo to be secretary of state in March, and chose Haspel to replace him as the spy chief.

Haspel immediately came under intense scrutiny for two specific episodes in her long career.

One was in 2002, when she ran a black site prison in Thailand where officers carried out waterboarding and other harsh tactics to extract information out of suspected al-Qaida militants. The other was in 2005, when she was based at CIA headquarters outside Washington and wrote a cable calling for videotapes of the waterboardings to be destroyed.

Democratic senators grilled Haspel on these events at her confirmation hearing before the Senate intelligence committee on May 9.

In several sharp exchanges with the senators, Haspel said she would not initiate any new detention and interrogation programs as CIA director. But she did not disavow the previous program, which ran from 2002 to 2008.

After that hearing, several senators said they needed additional information from Haspel. In a letter on Monday, she went beyond what she said in her public testimony.

"With the benefit of hindsight and my experience as a senior agency leader, the enhanced interrogation program is not one the CIA should have undertaken," she wrote in a letter to Sen. Mark Warner, a Virginia Democrat on the intelligence committee.

Shortly after her letter became public Tuesday, three Democratic senators, including Warner, announced their support for Haspel.

"I believe she is someone who can and will stand up to the president if ordered to do something illegal or immoral — like a return to torture," Warner said in a statement.

Haspel needed Democratic support to win confirmation because two Republican senators, Rand Paul of Kentucky and John McCain of Arizona, opposed her for her role in the interrogation program.

Copyright 2018 NPR. To see more, visit http://www.npr.org/.