GCHQ director Robert Hannigan is stepping down after only two years as chief of the cyber spy agency for “personal reasons,” the intelligence service has announced.

Hannigan took over GCHQ in 2014, just a year after National Security Agency contractor Edward Snowden exposed the vast extent of surveillance carried out by US and British intelligence services.

In a letter to Foreign Secretary Boris Johnson, Hannigan said a 20-year career in public service roles had “demanded a great deal of my ever patient and understanding family.”

“Now is the time for a change in direction,” he added.

The spymaster said he was proud of the work he had done at the agency and “how many lives have been saved in this country and overseas by the work of GCHQ.”

According to the latest @Snowden leaks, GCHQ spied on former colonies & African leaders, including UK allies. https://t.co/vRE1yIksfK — RT UK (@RTUKnews) December 9, 2016

Hannigan took over GCHQ in November 2014 at a time when the agency, and broader intelligence community, was under intense scrutiny following the Snowden revelations.

In a bid to appear more open, the spy chief made a series of public speeches both in Britain and the US.

The agency even launched a phone app for teenagers which teaches them encryption techniques and message security to ensure protection from surveillance. The application is called Cryptoy, and is aimed at getting teens more involved in science.

In his resignation letter to the foreign secretary, Hannigan wrote: “As you know, I have also initiated the greatest internal change within GCHQ for 30 years, and I feel that we are now well on the way to being fit for the next generation of security challenges to the UK in the digital age.

GCHQ to build ‘great firewall’ to protect against cyber threatshttps://t.co/Uhh2uimsz5pic.twitter.com/raB1MR12u1 — RT UK (@RTUKnews) September 14, 2016

“After a good deal of thought I have decided that this is the right time to move on and to allow someone else to lead GCHQ through its next phase. I am, like you, a great enthusiast for our history and I think it is right that a new director should be firmly embedded by our centenary in 2019. I am very committed to GCHQ’s future and will of course be happy to stay in post until you have been able to appoint a successor.”

In his reply, Johnson said: “You have led the renewal of some of our most important national security capabilities, which we continue to depend on every day to save lives from terrorism and to protect our interests and values. You also set the groundwork for a major transformation of our cyber defences, and put GCHQ on a path to meet the challenges of the future with your focus on technology and skills."

GCHQ has come under fire in recent years for its role in the surveillance state.

Documents leaked by Snowden last June revealed the agency regularly intercepts the emails of British MPs and peers, including privileged correspondence between parliamentarians and constituents.

GCHQ is known to play a key role in running the formerly secret Tempora computer system, which ‘bulk collects’ large amounts of Internet users’ personal data.