Its explanation lies in refraction of light in the atmosphere and is enhanced by atmospheric layering. It is usually observed from a low altitude where there is an unobstructed view of the horizon, such as on the ocean. Whilst we would expect to see a blue light, the blue is dispersed (this is why the sky is blue) and the green flash is visible from a fraction of a second to a couple of seconds duration.
With slight magnification the effect can be see on the top limb of the solar disk on most clear-day sunsets. However the flash effect requires a stronger layering of the atmosphere.