Image copyright GCHQ Image caption Robert Hannigan took over the role in 2014

The head of Britain's electronic surveillance agency GCHQ has resigned.

Robert Hannigan, who has held the post of GCHQ director since 2014, said he was stepping down for family reasons.

He said he was proud of his work but that 20 years in public service roles had "demanded a great deal of my ever patient and understanding family".

Foreign Secretary Boris Johnson said Mr Hannigan had "led the renewal" of national security capabilities to fight terrorism during his time at GCHQ.

Mr Hannigan was director general of defence and intelligence at the Foreign Office before taking over the leadership of GCHQ in 2014.

In a letter to the foreign secretary, he said he was proud of the work he had done and "how many lives have been saved in this country and overseas by the work of GCHQ" but added "now is the right time for a change in direction".

Mr Hannigan said it was "right" that a new director be in place ready for GCHQ's 100th anniversary in 2019, but he would stay in the post until a replacement was appointed.

'Cyber defences'

Sources have told BBC security correspondent Gordon Corera that the resignation was not the result of any concerns over policy in the UK or in the US.

Mr Johnson thanked him for his service, saying he had "set the groundwork for a major transformation of our cyber defences" during his tenure.

There will now be an internal competition within government to identify candidates for the job. Recommendations will then be sent to Mr Johnson and Prime Minister Theresa May for a final decision.

Mr Hannigan was born in Gloucestershire and is a married father-of-two.

He was previously responsible for the UK's first cyber security strategy, oversaw the first national security strategy, and chaired Cobra emergency committee meetings on terrorist incidents.

He also worked as principal adviser to then Prime Minister Tony Blair on the Northern Ireland peace process.