The active galaxy NGC 4151 has a crucial role as one of only two active galactic nuclei for which black hole mass measurements based on emission line reverberation mapping can be calibrated against other dynamical techniques1, 2, 3. Unfortunately, effective calibration requires accurate knowledge of the distance to NGC 4151, which is not at present available4. Recently reported distances range from 4 to 29 megaparsecs5, 6, 7. Strong peculiar motions make a redshift-based distance very uncertain, and the geometry of the galaxy and its nucleus prohibit accurate measurements using other techniques. Here we report a dust-parallax distance to NGC 4151 of megaparsecs. The measurement is based on an adaptation of a geometric method that uses the emission line regions of active galaxies8. Because these regions are too small to be imaged with present technology, we use instead the ratio of the physical and angular sizes of the more extended hot-dust emission9 as determined from time delays10 and infrared interferometry11, 12, 13, 14. This distance leads to an approximately 1.4-fold increase in the dynamical black hole mass, implying a corresponding correction to emission line reverberation masses of black holes if they are calibrated against the two objects with additional dynamical masses.