Two-photon imaging of bulk-loaded calcium dyes can record action potentials (APs) simultaneously from dozens of spatially resolved neurons in vivo. Extending this technique to awake animals, however, has remained technically challenging due to artifacts caused by brain motion. Since in two-photon excitation microscopes image pixels are captured sequentially by scanning a focused pulsed laser across small areas of interest within the brain, fast displacements of the imaged area can distort the image nonuniformly. If left uncorrected, brain motion in awake animals will cause artifactual fluorescence changes, masking the small functional fluorescence increases associated with AP discharge. We therefore present a procedure for detection and correction of both fast and slow displacements in two-photon imaging of awake animals. Our algorithm, based on the Lucas-Kanade framework, operates directly on the motion-distorted imaging data, requiring neither external signals such as heartbeat nor a distortion-free template image. Motion correction accuracy was tested in silico over a wide range of simplified and realistic displacement trajectories and for multiple levels of fluorescence noise. Accuracy was confirmed in vivo by comparing solutions obtained from red and green fluorophores imaged simultaneously. Finally, the accuracy of AP detection from motion-displaced bulk-loaded calcium imaging is evaluated with and without motion correction, and we conclude that accurate motion correction as achieved by this procedure is both necessary and sufficient for single AP detection in awake animals.