The director-general of MI5 said the threat from terrorists was on a scale he had never seen in his 32-year career.