We introduce a complex-plane generalization of the consecutive level-spacing distribution, used to distinguish regular from chaotic quantum spectra. Our approach features the distribution of complex-valued ratios between nearest-and next-to-nearest neighbor spacings. We show that this quantity can successfully detect the chaotic or regular nature of complex-valued spectra. This is done in two steps. First, we show that, if eigenvalues are uncorrelated, the distribution of complex spacing ratios is flat within the unit circle, whereas random matrices show a strong angular dependence in addition to the usual level repulsion. The universal fluctuations of Gaussian Unitary and Ginibre Unitary universality classes in the large-matrix-size limit are shown to be well described by Wigner-like surmises for small-size matrices with eigenvalues on the circle and on the two-torus, respectively. To study the latter case, we introduce the Toric Unitary Ensemble, characterized by a flat joint eigenvalue distribution on the two-torus. Second, we study different physical situations where nonhermitian matrices arise: dissipative quantum systems described by a Lindbladian, non-unitary quantum dynamics described by nonhermitian Hamiltonians, and classical stochastic processes. We show that known integrable models have a flat distribution of complex spacing ratios whereas generic cases, expected to be chaotic, conform to Random Matrix Theory predictions. Specifically, we were able to clearly distinguish chaotic from integrable dynamics in boundary-driven dissipative spin-chain Liouvillians and in the classical asymmetric simple exclusion process and to differentiate localized from delocalized phases in a nonhermitian disordered many-body system.