Context. The second-generation instrument SPHERE, dedicated to high-contrast imaging, will soon be in operation on the European Very Large Telescope. Such an instrument relies on an extreme adaptive optics system coupled with a coronagraph that suppresses most of the diffracted stellar light. However, the coronagraph performance is strongly limited by quasi-static aberrations that create long-lived speckles in the scientific image plane, which can easily be mistaken for planets. Aims. The wavefront analysis performed by SPHERE's adaptive optics system uses a dedicated wavefront sensor. The ultimate performance is thus limited by the unavoidable differential aberrations between the wavefront sensor and the scientific camera, which have to be estimated and compensated for. In this paper, we use the COFFEE approach to measure and compensate for SPHERE's quasi-static aberrations. Methods. COronagraphic Focal-plane waveFront Estimation for Exoplanet detection (COFFEE), which consists in an extension of phase diversity to coronagraphic imaging, estimates the quasi-static aberrations, including the differential ones, using only two focal plane images recorded by the scientific camera. In this paper, we use coronagraphic images recorded from SPHERE's infrared detector IRDIS to estimate the aberrations upstream of the coronagraph, which are then compensated for using SPHERE's extreme adaptive optics loop SAXO. Results. We first validate the ability of COFFEE to estimate high-order aberrations by estimating a calibrated influence function pattern introduced upstream of the coronagraph. We then use COFFEE in an original iterative compensation process to compensate for the estimated aberrations, leading to a contrast improvement by a factor that varies from 1.4 to 4.7 between 2λ/D and 15λ/D on IRDIS. The performance of the compensation process is also evaluated through simulations. An excellent match between experimental results and these simulations is found.