The heart regulates its beating by using a carefully-tuned cascade of electrical-impulses that trigger each other to keep it in a steady rhythm, much like a pendulum clock. When these impulses get out of whack, like when you stick a fork in the toaster and subject your body to a 60Hz alternating current, the effect is the same as shaking said pendulum clock....everything kind of siezes up and and finds a new stable state, which is, unfortunately, a non-productive quivering.

A defibrillator is almost exactly like a reset switch for your heart. Applying a strong direct current zeros all unstable nerves, and allows the heart to start itself again from a base state.

When the heart is stopped completely, it is not a problem that defibrillation can solve. Instead, you need to do something like massage the heart.