The CIA’s deputy director plans to retire and will be replaced by White House lawyer and agency outsider Avril D. Haines, Director John O. Brennan said Wednesday.

Haines, who will succeed career officer Michael Morell on Aug. 9, has served for three years as President Obama’s deputy counsel in charge of national security issues and as legal adviser to the National Security Council. Although she has never worked inside the intelligence agency, “she knows more about covert action than anyone in the U.S. government outside of the CIA,” Brennan said in his first interview since becoming CIA director in March.

The surprise move gives Brennan an ally in the CIA’s executive suite who helped him with the revision of drone-campaign rules that was recently announced by Obama. Unlike an agency insider, Haines has no direct investment in any of the counterterrorism programs that Brennan has indicated he will seek to rein in.

In a message to the CIA on Wednesday afternoon, Brennan emphasized that Haines, 43, has worked closely with senior national security officials. “She has participated in virtually every Deputies and Principals Committee meeting over the past two years and chairs the Lawyers’ Group that reviews the Agency’s most sensitive programs,” the statement said.

Obama nominated Haines just two months ago as legal counsel for the State Department, where she worked previously as a lawyer. Brennan said he spoke to Secretary of State John F. Kerry, who has been slow to fill a number of vacant diplomatic jobs, about the change. Haines also worked as deputy counsel for the Senate Foreign Relations Committee when both Kerry and Vice President Joe Biden were members of that panel.

The highly regarded Morell, a 33-year CIA veteran who twice served as acting director, said in an interview that he decided last month to retire because “I want to and I need to devote more attention to my family.” Morell has three college-age children.

In a series of high-powered jobs, Morell delivered the President’s Daily Brief to George W. Bush. He said he was “probably the only person on the planet” at the side of U.S. presidents during both the Sept. 11, 2001, attacks and “when we brought Osama bin Laden to justice.”

Brennan and Morell spoke of their professional and personal closeness — they both started at the CIA in 1980 — and emphasized that the retirement was Morell’s choice. Each said he had recommended the other as Obama’s new CIA director before Brennan’s nomination early this year.

Brennan and Morell both joined the CIA in 1980; Brennan left after 25 years for the private sector and reentered government in 2009 as Obama’s top counterterrorism adviser. As director, he has moved to counteract the CIA’s expansion into what the agency calls “direct action,” including drone strikes, and reinvigorate its core functions of intelligence gathering and analysis.

Brennan said he turned toward Haines based on her performance at the White House, where “I spent a lot of time on matters involving the law” and “noticed similarities between the intelligence and legal professions.” Both, he said, need to make sure “facts are correct and distinguish between facts, analysis, assessments and inference. Avril epitomizes those qualities.”

“When I was told by Michael that he was leaving . . . I wrote down different types of qualities I wanted. One of those was to make sure the individual understands that the role of intelligence is not to advocate for policy positions, but to make sure we are able to collect the best intelligence possible and present it to policymakers as concisely and clearly as possible.”

White House Chief of Staff Denis McDonough said Obama valued Haines’s “independence of thought, fierceness of advocacy and rigor in how analytically she attacks problems.”

Others expressed surprise at her selection for such a senior intelligence job and noted Haines’s extensive background at the State Department, which has often been at odds with the CIA in policy battles over drone strikes and their diplomatic consequences.

“It’s an interesting and unusual pick,” said a former U.S. official who worked with Brennan and Haines on intelligence issues and spoke on the condition of anonymity to discuss internal personnel moves. “Avril is extremely talented but obviously doesn’t come out of the intelligence community. The ability of outsiders to work in the community is always an open question.”

Inside the CIA, Morell said, the perception of Haines is “not that she’s going to bring some kind of left-wing perspective to this place, but that she’s somebody who’s actually helped us get the job done” in her role as National Security Council counsel.

Haines was described by colleagues as highly polished with a remarkable grasp of the legal complexities of national security issues. But some wondered whether she was a forceful enough personality to help push through changes that some at the agency might resist.

The selection was also revealing about Brennan, who prizes collegiality within his inner circle and who, in his personnel moves, has not turned to anyone with close ties to the CIA’s controversial interrogation or targeted killing programs.

“Given how insular this place is, I think it’s important for there to be outsiders here,” Morell said. “We need fresh perspectives. With a director who is of this place, and who spent so much of his time here and knows this place so well, I told John I actually think that the person who replaces me [should not be] of this place.”

Previous directors, including Leon E. Panetta and David H. Petraeus, began their tenures as CIA outsiders and selected deputies who could help navigate internal politics and cement relationships with the operational and analytic directorates.

Daniel Benjamin, who previously served as the top counterterrorism official at the State Department, praised Haines as “an extraordinary talent. She’s incredibly sharp, hardworking understands all the angles.”

The Haines pick also moves a woman into the No. 2 job for the first time. The selection comes at a sensitive moment on gender issues for the agency. In recent months, former secretary of state Madeleine K. Albright completed a CIA-sanctioned report that warned that failing to promote women was undermining the agency’s long-term effectiveness.

Although there are several other women in senior CIA positions — including his chief of staff — Brennan passed over a woman for the job of head of the clandestine service who had been working in that position in an acting capacity for months. The woman, who remains undercover, was regarded as a controversial candidate for the job because of her deep ties to the agency’s use of brutal interrogation methods after the Sept. 11 attacks.

“It’s lost on nobody that Avril will be the first female in the history of the CIA” to hold the No. 2 job there, Morell said. “I think it’s terrific for the women of CIA that they’re going to have another role model. But the fact that she’s a female, while it’s nice to have . . . she really did earn this on her merits.”

Haines is a 2001 graduate of Georgetown University Law Center.

The job of deputy CIA director is a presidential appointment that does not require Senate confirmation.