Behavioural engagement can enhance sensory perception. However, the neuronal mechanisms by which behavioural states affect stimulus perception remain poorly understood. Here we record from single units in auditory cortex of rats performing a self-initiated go/no-go auditory task. Self-initiation transforms cortical tuning curves and bidirectionally modulates stimulus-evoked activity patterns and improves auditory detection and recognition. Trial self-initiation decreases the rate of spontaneous activity in the majority of recorded cells. Optogenetic disruption of cortical activity before and during tone presentation shows that these changes in evoked and spontaneous activity are important for sound perception. Thus, behavioural engagement can prepare cortical circuits for sensory processing by dynamically changing sound representation and by controlling the pattern of spontaneous activity.