Exoplanets orbiting close to their parent stars may lose some fraction of their atmospheres because of the extreme irradiation. Atmospheric mass loss primarily affects low-mass exoplanets, leading to the suggestion 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σ), far beyond the 0.69% optical transit depth. The ultraviolet transits repeatedly start about two hours before, and end more than three hours after the approximately one hour 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 about 108-109 grams per second, which 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.