Robert Hannigan, the head of the Government Communications Headquarters (GCHQ), informed Foreign Secretary Boris Johnson of his decision.
The 51-year-old said he had been "lucky enough to have some extraordinary roles in public service over the last 20 years".
But he added: "They have all demanded a great deal of my ever patient and understanding family, and now is the right time to change direction".
Hannigan was director general of defence and intelligence at the Foreign Office before taking over at GCHQ.
More From This Section
"I am... Proud of the relentless 24-hour operational effort against terrorism, crime and many other national security threats," Hannigan wrote.
"While this work must remain secret, you will know how many lives have been saved in this country and overseas by the work of GCHQ," he said.
Hannigan took over at GCHQ at a time when it was under a shadow following leaks by former National Security Agency contractor Edward Snowden about the extent of British-US data surveillance.