Consider a falling object. A falling object is attracted by the Earth, and as it falls, the object loses potential energy and releases it as kinetic energy. On the other hand, an object traveling upwards must be given an initial kinetic energy to escape the Earth's gravitational pull.
In the same manner, an electron being attracted by a nucleus loses potential energy and releases energy in the form of heat (kinetic energy) or light. Similarly, an electron moving away from a nucleus, must absorb energy in order to escape the attraction of the nucleus.
[this is of course, a very simplified analogy because the sittuation isn't as simple as the electron being attracted by the nucleus, but it illustrates the concept well enough]