Why is energy released as electrons move?
The previous answer is correct. I just wanted to add that atoms, electrons and generally matter, tries to ''organise'' itself in order to adopt a state, where it would have the lowest energy possible.
An electronegative atom tends to attract electrons and has the ability of handling their charge better. Thus when an electron moves from a less electronegative atom to a more electronegative one, it is like moving from a state of high energy to a state of low energy. This is also described as realease of energy.