Very nice question! In fact, this was a question that scientists asked themselves only one hundred years ago. The answer is that the Sun is not composed of gas burning in a “traditional” way. The Sun in fact works more like a nuclear reactor – or I should say, an Hydrogen bomb.
The Sun is composed mainly of gaseous hydrogen. Now, hydrogen DOES burn in the traditional way. “Burning” something however is merely a chemical reaction: it means the atoms of hydrogen are stitched together with an atom of oxygen, forming water, and energy is released in the process (this happens because water has less energy than hydrogen and oxygen combined: the excess is liberated as heat and light!). However, what happens in the Sun is a nuclear reaction: hydrogen atoms are smashed together so hard that they “fuse” and become a different atom altogether: an helium atom! This produces a lot more energy, and allows the Sun to shine. It is possible only because the temperature in the core of the Sun is around 15,000,000 degrees! This is also why reproducing nuclear fusion on Earth is so hard – doing it as a bomb is possible, but keeping it under control to produce energy is very difficult. If we could do it, though, that would be an excellent form of energy – and much cleaner than ‘ordinary’ nuclear energy!
By the way, the nuclear fusion does not stop to hydrogen atoms being smashed together into becoming helium. Helium atoms are fused as well, and become more and more different elements. A star stops working when it has no more atoms to fuse: this happens because ultimately it forms some elements (iron, mostly) that are not ‘convenient’ to fuse any more – meaning that fusing them costs energy, instead of producing it. That’s when the star shuts down and either explodes (going “supernova”) or becomes a white dwarf. Our Sun still has enough hydrogen to go for 5 billion years, though, so we’re perfectly okay!