A varistor protects electronic circuits from voltage spikes by acting as a voltage-dependent resistor. When a voltage spike occurs, the varistor's resistance decreases, effectively shunting the excess voltage away from the sensitive components of the circuit. This helps prevent damage to the electronic components by limiting the voltage across them.