image credit: NASA, ESA, H. Bond (STScI), R. Ciardullo (Penn State), and the Hubble Heritage Team (AURA/STScI); image source; larger image
When the Sun reaches the end of its life, its outer layers will drift into space, an intricate cloud illuminated by its hot, dense core, as in this false-color image of a planetary nebula and white dwarf. For more details, see this page on the death of solar-mass stars.
How a star lives and dies depends upon its mass. For an overview of the lifetime of different types of stars, see The Life and Death of Stars. You should also see the Interactive Guide to Stellar Evolution and, for very thorough explanations, the Stellar Evolution pages from the Chandra website.
Death Star: A Bad Day In the Milky Way
Another possible fate for especially massive stars is to explode in a hypernova, causing a gamma-ray burst. To learn about the effect a gamma-ray burst would have on Earth, check out Death Star: A Bad Day In the Milky Way.