Betelgeuse, a nearby red supergiant, is a runaway star with a powerful stellar wind that drives a bow shock into its surroundings. This picture has been challenged by the discovery of a dense and almost static shell that is three times closer to the star than the bow shock and has been decelerated by some external force. The two physically distinct structures cannot both be formed by the hydrodynamic interaction of the wind with the interstellar medium. Here we report that a model in which Betelgeuse's wind is photoionized by radiation from external sources can explain the static shell without requiring a new understanding of the bow shock. Pressure from the photoionized wind generates a standing shock in the neutral part of the wind and forms an almost static, photoionization-confined shell. Other red supergiants should have significantly more massive shells than Betelgeuse, because the photoionization-confined shell traps up to 35 per cent of all mass lost during the red supergiant phase, confining this gas close to the star until it explodes. After the supernova explosion, massive shells dramatically affect the supernova lightcurve, providing a natural explanation for the many supernovae that have signatures of circumstellar interaction.