A former head of GCHQ resigned from his post after it emerged he gave a character reference to a paedophile priest who went on to reoffend, it has been alleged.

Robert Hannigan was in charge of Britain’s surveillance agency for just over two years between 2014 and 2017.

His resignation in January 2017 came out of the blue and surprised security observers. Hannigan, then 51, suggested that he wanted to prioritise his family. In his resignation letter he said his 20-year career as a public servant had “demanded a great deal of my ever patient and understanding family and now is the right time for a change in direction”.

The Mail on Sunday has reported that the real reason was his involvement in the case of Father Edmund Higgins, a Catholic priest and family friend. Sources close to the case have confirmed to The Guardian that this is the case.

The Mail on Sunday said Hannigan had given a character reference for Higgins, a parish priest in Richmond, in 2013 after he had admitted possession of child abuse images sent to him via online chatrooms. Higgins was spared jail when the judge at Isleworth crown court gave him a suspended prison sentence.

Higgins, now with the name Edmund Black, was sentenced to 31 months in jail in June last year after he pleaded guilty to charges involving child abuse images. The court heard that the former priest would watch and share child abuse videos, including one that involved a baby.

The Mail on Sunday reports that it was during the National Crime Agency investigation into online chatrooms that Higgins and his links to Hannigan were discovered and No 10 was alerted. Hannigan reportedly offered to resign to avoid dragging GCHQ into a scandal and did so with Theresa May’s blessing.

The media was told that his resignation was mainly for family health reasons.

Hannigan told the newspaper that Higgins had been a close family friend for 20 years. “After he pleaded guilty to child sexual imagery offences in 2013, we submitted a character reference on our knowledge of him to the court in good faith.

“His subsequent criminal actions appalled us and have shown that our judgment was completely wrong. When I later became director of GCHQ, all the correct steps were taken in relation to my involvement in this case and this was verified by government lawyers. This is a personal family matter. We will not be making further comment.”

While at GCHQ, Hannigan led a push to make the agency more transparent. The then foreign secretary, Boris Johnson, praised him for setting the groundwork for a transformation of Britain’s cyber defences.

Before taking charge of the agency Hannigan had occupied a number of important roles in the civil service.

While at the Northern Ireland office from 2005 to 2007 he was a key adviser to Tony Blair during negotiations between republicans and unionists, coming up with the idea of a diamond-shaped table so Gerry Adams and Ian Paisley could be close to each other without being side by side.

He later advised Gordon Brown on intelligence and security, and in 2010 became director general for defence and intelligence at the Foreign Office.

The Tablet listed him as the third most powerful lay Catholic in Britain in 2015, reporting that he had trained as a priest at the Allen Hall seminary in Chelsea.

Since GCHQ, Hannigan has worked in the private sector as European chairman and global head of strategy at the cybersecurity company BlueVoyant.