Computing a correlation between a pair of time series is a routine task in disciplines from biology to climate science. How do we test whether such a correlation is statistically significant (i.e. unlikely under the null hypothesis that the time series are independent)? This problem is made especially challenging by two factors. First, time series typically exhibit autocorrelation, which renders standard statistical tests invalid. Second, researchers are increasingly turning to nonlinear correlation statistics with no known analytical null distribution, thus rendering parametric tests inviable. Several statistical tests attempt to address these two challenges, but none is perfect: A few are valid only under restrictive data conditions, others have differing degrees of correctness depending on user-supplied parameters, and some are simply inexact. Here we describe the truncated time-shift procedure, which can be used with any correlation statistic to test for dependence between time series. We show that this test is exactly valid as long as one time series is stationary, a minimally restrictive requirement among nonparametric tests. Using synthetic data, we demonstrate that our test performs correctly even while other tests suffer high false positive rates. We apply the test to data sets from climatology and microbiome science, verifying previously discovered dependence relationships.