The image quality of a two-photon microscope is often degraded by wavefront aberrations induced by the specimen. We demonstrate here that resolution and signal size in two-photon microcopy can be substantially improved, even in living biological specimens, by adaptive wavefront correction based on sensing the wavefront of coherence-gated backscattered light (coherence-gated wavefront sensing, CGWS) and wavefront control by a deformable mirror. A nearly diffraction-limited focus can be restored even for strong aberrations. CGWS-based wavefront correction should be applicable to samples with a wide range of scattering properties and it should be possible to perform real-time pixel-by-pixel correction even at fast scan speeds.