Few things are as powerful (or as majestic) as the death of a star. These events literally reshape solar systems and forever alter the structure of the cosmos. Recently, NASA and the European Space Agency (ESA) captured the final moments of a dying star, thanks to the Hubble Space Telescope.
As stars enter the final stages of their life, they begin to throw off massive amounts of material. This results in something known as "planetary nebula." The name is a bit of a misnomer, as these structures are not the place where new worlds are born. Rather, a planetary nebula is an shell of ionized gas that radiates out from a star during the final moments of its life. The gas is ejected from old red giant stars late in their lives because they can no longer support themselves by fusion reactions in their center.
As the National Optical Astronomy Observatory (NOAO) notes, when fusion starts to slow:
The gravity from the material in the outer part of the star takes its inevitable toll on the structure of the star, and forces the inner parts to condense and heat up. The high temperature central regions drive the outer half of the star away in a brisk stellar wind, lasting a few thousand years. When the process is complete, the remaining core remnant is uncovered and heats the now distant gases and causes them to glow.
In the image above, the star's death resulted in the stunning planetary nebula known as NGC 6565. This portion of a stars death can last 10,000 years (give or take a few years, depending on the size and the structure of the star). That may seem like a long time to us, but given the 10 billion year lifespan of stars like this, it is really only a blink in the cosmological time scale.
Seen here, after enough material was ejected from the star, the inner core was exposed. This allowed the ultraviolet radiation to excite the surrounding gas; however, the level of excitement was not universal, which resulted in this wide array of colors.
As previously mentioned this stage of a star's life (or death), the planetary nebula portion, lasts for about 10,000 years. After this, the nebula will fade as the star starts to transition, cooling and shrinking to become a white dwarf. At such a juncture, the light output diminishes significantly, the gas is no longer excited, nnd the nebula fades from view.
So enjoy the view while you still can.