The responses of neocortical cells to sensory stimuli are variable and state dependent. It has been hypothesized that intrinsic cortical dynamics play an important role in trial-to-trial variability; the precise nature of this dependence, however, is poorly understood. We show here that in auditory cortex of urethane-anesthetized rats, population responses to click stimuli can be quantitatively predicted on a trial-by-trial basis by a simple dynamical system model estimated from spontaneous activity immediately preceding stimulus presentation. Changes in cortical state correspond consistently to changes in model dynamics, reflecting a nonlinear, self-exciting system in synchronized states and an approximately linear system in desynchronized states. We propose that the complex and state-dependent pattern of trial-to-trial variability can be explained by a simple principle: sensory responses are shaped by the same intrinsic dynamics that govern ongoing spontaneous activity.