A tunable energy-chirp compensator was used to remove a correlated energy chirp from the 60-MeV beam at the Brookhaven National Laboratory Accelerator Test Facility. The compensator operates through the interaction of the wakefield of the electron bunch with itself and consists of a planar structure comprised of two alumina bars with copper-plated backs separated by an adjustable beam aperture. By changing the gap size, the correlated energy chirp of the electron bunch was completely removed. Calculations show that this device, properly scaled to account for the electron bunch charge and length, can be used to remove residual correlated energy spread at the end of the linacs used for free-electron lasers. The experimental results are shown to be in good agreement with numerical simulations. Application of this technique can significantly simplify linac design and improve free-electron lasers performance.