Cardioversion or defibrillation of the heart is carried out by passing electrical energy through the heart. An electrical energy storage device, such as a battery and capacitor, are connected to an electronic processor. The energy storage device and the electronic processor are sized to be implantable within the body of the patient. Two leads are subcutaneously implanted and connected to the energy storage device under control of the processor. An electrode is connected to each lead, and are also subcutaneously implanted, the first able proximate the heart and an anterior portion of the ribcage in the patient's chest, and the second proximate the heart and a posterior portion of the ribcage in the patients back. Sensors transmit information to the processor relating to heart function, and under control of software, the processor causes the electrodes to be energized to restore normal heart function.