Britain and the European Union must build a close security partnership after Brexit to foil Islamic State militant attacks and counter Russia's malign attempts to subvert Western democracies, the head of Britain's domestic spy agency said.