The green flash is a real but seldom seen phenomenon that can be understood though the magic of some simple physics. At the root of it is the fact that by the time we see the last sliver of the sun set, the actual sun had already passed the edge of the horizon minutes earlier. What we are seeing is refracted image of the sun as it is bent around the horizon. The discrepancy is only about 0.5 degrees, which is about the apparent diameter of the sun.

Your standard post-rainstorm rainbow is visible because the different light wavelengths (therefore colors) are bent differing amounts by suspended water droplets; the same thing occurs to the image of the sun as it sets, but by the atmosphere itself. It gets separated into series of overlapping disks, in the order of ROY G BIV. They slide behind the horizon, with red first and violet last, each separated by about 0.05 degrees.

The blue, indigo, and violet colors are scattered too well by the atmosphere to be visible (for the same reason the sky is blue) The yellow and orange are absorbed by the ozone layer, so they are not terribly visible. So we see a bright red sunset. And then, at the very end, if the conditions are right, we will see a small arc of the green flash following it down.

The conditions that make for best viewing (some observed in the write-ups above):
1. A very clear sky.
2. Higher latitudes, because longer, slower sunsets make it last longer. (Although it's fully visible at any latitude.)
3. An extremely distant apparent horizon. This gives the chance for the greatest degree of separation of the different colors.
4. Standing at sea level. This might seem counterintuitive, but part of what makes the green flash work is mirage effect.

See also Why the sun is yellow.

For a nice picture of all this, go to
http://www.isc.tamu.edu/~astro/research/sandiego.html