The C.I.A.’s deputy director, Michael J. Morell, is retiring after 33 years at the agency and will be replaced by Avril D. Haines, the top lawyer at the National Security Council, the C.I.A.’s director, John O. Brennan, announced Wednesday.

The switch will put a woman in one of the agency’s top two jobs for the first time. Ms. Haines is an unusual choice because she is not an intelligence professional, though in her two years at the White House she has been deeply involved in intelligence programs and got to know Mr. Brennan when he was President Obama’s counterterrorism adviser.

In April, the president had nominated Ms. Haines to become the legal adviser at the State Department, a job in which she would also have been the first woman. But with Mr. Morell’s departure, he evidently decided to shift her to the C.I.A. post.

The agency’s deputy director is not subject to Senate confirmation.

Mr. Morell, 54, is leaving voluntarily, officials said, after a full career that has included two recent stints as acting director of the spy agency, first after the departure of Leon E. Panetta in 2011 and then after the resignation of David H. Petraeus last year over a sex scandal. He was a leading candidate for the top job, but Mr. Obama chose Mr. Brennan in January, and colleagues said then that Mr. Morell was likely to retire.