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.2M(Jupiter)) orbiting the star V 391 Pegasi at a distance of about 1.7 astronomical units (au), with a period of 3.2 years. 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.7 au, while the orbital distance of the planet during the stellar main-sequence phase is estimated to be about 1 au. This detection of a planet orbiting a post-red-giant star demonstrates that planets with orbital distances of less than 2 au can survive the red-giant expansion of their parent stars.