How does an internal defibrillator function?

Monitor. It monitor abnormally rapid atrial and ventricular rate with certain parameter and it will deliver a shock if it detects rapid ventricular tachycardia or fibrillation.
Shocks heart. It monitors the heart rhythm looking for certain dangerous types of rapid heart rhythm. If it detects such a rhythm, it delivers a shock to the heart which hopefully restores a regular rhythm. It also has the capacity to pace the heart if the beating is too slow.