Consider an electron which is brought close to the nucleus of the atom from an infinite distance, the energy of the electron-nucleus system:
When an electron is brought closer to the nucleus, the potential energy of the electron-nucleus system decreases due to the attractive force between them. This decrease in potential energy results in a lower total energy of the system.