This paper deals with the correction of distortions in EPI acquisitions. Echo-planar imaging (EPI) data is used in functional resonance imaging (fMRI) and in diffusion tensor MRI (dMRI) because of its impressive ability to collect data rapidly. However, these data contain geometrical distortions that degrade the quality of the scans and disturb their interpretation. In this paper, we present a fully automatic 3D registration algorithm to correct these distortions. The method is based on the minimization of a cost function (including mutual information and regularization) with a hierarchical multigrid optimization scheme. We present a numerical evaluation on simulated data and results on real data.