The wave properties of light, particularly its coherence, are responsible for interference effects, which can be exploited in powerful imaging applications. Coherent diffractive imaging relies heavily on coherence and has recently experienced rapid growth. Coherent diffractive imaging recovers an object from its diffraction pattern by computational phasing with the potential of wavelength-limited resolution. Diminished coherence results in reconstructions that suffer from artefacts or fail completely. Here we demonstrate ab initio phasing of partially coherent diffraction patterns in three dimensions, while simultaneously determining the coherence properties of the illuminating wavefield. Both the dramatic improvements in image interpretability and the three-dimensional evaluation of the coherence will have broad implications for quantitative imaging of nanostructures and wavefield characterization with X-rays and electrons.