Exoplanets orbiting close to their parent stars could lose some fraction of their atmospheres because of the extreme irradiation. Atmospheric mass loss primarily affects low-mass exoplanets, leading to suggest that hot rocky planets might have begun as Neptune-like, but subsequently lost all of their atmospheres; however, no confident measurements have hitherto been available. The signature of this loss could be observed in the ultraviolet spectrum, when the planet and its escaping atmosphere transit the star, giving rise to deeper and longer transit signatures than in the optical spectrum. Here we report that in the ultraviolet the Neptune-mass exoplanet GJ 436b (also known as Gliese 436b) has transit depths of 56.3 +/- 3.5% (1 sigma), far beyond the 0.69% optical transit depth. The ultraviolet transits repeatedly start ~2 h before, and end >3 h after the ~1 h optical transit, which is substantially different from one previous claim (based on an inaccurate ephemeris). We infer from this that the planet is surrounded and trailed by a large exospheric cloud composed mainly of hydrogen atoms. We estimate a mass-loss rate in the range of ~10^8-10^9 g/s, which today is far too small to deplete the atmosphere of a Neptune-like planet in the lifetime of the parent star, but would have been much greater in the past.