Release of energy as light from the movement of a valence electron from an excited state to its ground state.
A heat heat source excites the valence electrons from their ground state into a higher-energy “excited state” shell. The electrons then spontaneously return to their previous, more stable ground state shell and release the energy in the form of visible light.
The specific color changes for different elements are because of the differences in the individual electron shell energies. Electrons can only change shells with the adsorption or emission of specific amounts, or quanta, of energy.
Thus, whatever the energy (and color) of the flame, once an electron has been excited to a higher-energy shell it can only return to a lower-energy shell with the release of a very specific energy and wavelength of emitted light. This emitted light is what is observed as a change in the flame color.
A handy infographic of elements and flame colors can be found here:
Other examples and a good discussion of what is happening, and how to perform the tests safely is here: