The transport of intensity equation (TIE) offers a convenient method to retrieve the phase of a wave function from maps of the irradiance (images) recorded at different planes along the optic axis of an optical system. However, being a second-order partial differential equation, even for noise-free data a unique solution of the TIE requires boundary conditions to be specified which are generally not accessible experimentally, jeopardizing retrieval of the low-frequency information in particular. Here we introduce an iterative algorithm which forgoes the need for explicit boundary conditions and combines the well-known reciprocal space solution of the TIE with the charge-flipping algorithm that has originally been developed to solve the crystallographic phase problem in X-ray diffraction. Application of this algorithm to experimental data and comparison with conventionally used algorithms demonstrates an improved retrieval of the low spatial frequencies of the phase.