After the initial discoveries fifteen years ago, over 200 extrasolar planets have now been detected. Most of them orbit main-sequence stars similar to our Sun, although a few planets orbiting red giant stars have been recently found. When the hydrogen in their cores runs out, main-sequence stars undergo an expansion into red-giant stars. This expansion can modify the orbits of planets and can easily reach and engulf the inner planets. The same will happen to the planets of our Solar System in about five billion years and the fate of the Earth is matter of debate. Here we report the discovery of a planetary-mass body (Msini = 3.2MJupiter) orbiting the star V391 Pegasi at a distance of about 1.7 astronomical units (AU), with a period of 3.2years. This star is on the extreme horizontal branch of the Hertzsprung-Russell diagram, burning helium in its core and pulsating. The maximum radius of the red-giant precursor of V 391 Pegasi may have reached 0.7AU, while the orbital distance of the planet during the stellar main-sequence phase is estimated to be about 1AU. This detection of a planet orbiting a post-red-giant star demonstrates that planets with orbital distances of less than 2AU can survive the red-giant expansion of their parent stars.