Lord Evans said: "There's no doubt that we are still facing a severe terrorist threat but I think its also important to put this in a slightly longer context because right the way back from the 1990s we have been experiencing difficulties from Islamist terrorists of one sort or another.

"Over that period the threat has come and gone but the underlying threat has continued.

"Since 2013 there have been 19 attempted attacks that have been disrupted and even since the attack at Westminster we are told there have been six disruptions, so this is a permanent state of preparedness."

'Sleepless nights'

He added: "We're at least 20 years into this. My guess is that we will still be dealing with the long tail in over 20 years' time.

"I think this is genuinely a generational problem. I think we are going to be facing 20 to 30 years of terrorist threat and therefore we need, absolutely critically, to persevere."

The BBC's security correspondent Frank Gardner, who conducted the interview, said Lord Evans was also asked about being responsible for sending people inside terrorist cells to gather intelligence.

The former MI5 head said it often was "just sleepless nights" and "nail-biting" but measures to protect staff were taken.

Analysis

Image copyrightGetty Images

By BBC home affairs correspondent Daniel Sandford

The head of national counter-terrorism policing, Assistant Commissioner Mark Rowley, has said a "whole-system effect" was now needed in which the public, other public services and agencies, and businesses all need to work together to keep the UK safe.

It is an acknowledgement that after the bloody months of March, May and June the system for tackling terrorism will have to change.

There are already internal reviews of how the police and security services dealt with their previous knowledge of some of the perpetrators of this year's attacks. But this is more than that.

It is a plea for help, on the day that Lord Evans, who stepped down as director general of MI5 in 2013, warned that the threat from terrorism will be with us for 20 or 30 more years.

Lord Evans also warned that the "internet of things" - in which vehicles and domestic devices are all connected to the internet - will need to be made more secure to reduce emerging cyber threats.

He said it was concerning that Russia had apparently been interfering in the democratic processes of some Western countries.

Lord Evans said it was something the UK needed to be alert to, as he would be "very surprised" if it was not a target as well.

Speaking on Radio 4's Today, the head of national counter-terrorism policing called the current Islamist threat a "cultish movement" compared to al-Qaeda and the IRA who were "a very tight network of wicked individuals".

Assistant Commissioner Mark Rowley said: "You've got that range of people who have picked up that ideology and come up with their own plan based on the encouragement of the propaganda all the way through to the more organised directed attacks.

"This widening cohort of people that we're concerned about and our ability to keep our radar on them is no longer just a job for police and security services."