We consider using phase retrieval (PR) to correct phase aberrations in an optical system. Three measurements of the point-spread function (PSF) are collected to estimate an aberration. For each measurement, a different defocus aberration is applied with a deformable mirror (DM). Once the aberration is estimated using a PR algorithm, we apply the aberration correction with the DM, and measure the residual aberration using a Shack-Hartmann wavefront sensor. The extended Nijboer-Zernike theory is used for modelling the PSF. The PR problem is solved using both an algorithm called PhaseLift, which is based on matrix rank minimization, and another algorithm based on alternating projections. For comparison, we include the results achieved using a classical PR algorithm, which is based on alternating projections and uses the fast Fourier transform.