We present a method to invert viscoacoustic waveforms. The waveform inversion is based on a new forward algorithm for waves propagating through viscoacoustic media. The algorithm represents the wavefield in terms of a summation over nonstationary raypaths. The amplitudes at the caustics are computed correctly. The inclusion of nonstationary raypaths makes it possible to compute sensitivity functions for both velocity and attenuation. The sensitivity functions lead to a linearized formulation of the waveform inversion. The inversion is applied to two 2-D data sets that previously had been matched using only velocity. The first data set consists of crosswell data obtained from a tank filled with a water-saturated sand. The second data set was obtained after injecting a nonaqueous-phase liquid into the tank. The inclusion of attenuation significantly improves the fit to the data, especially in the case of the second experiment. A misfit reduction of 80% was obtained, whereas the misfit reduction after inversion for velocity only was 40%. The Q values obtained for the two experiments (Q = 60–100 before the injection and Q = 10–20 in the second experiment) fall within the range predicted by other experiments.