An algebraic criterion for the ultraviolet finiteness of quantum field theories