Domestic security agency making ‘biggest shift in a generation’ as it also contends with threats from Russia and Iran