Magnesium anode rods protect water heater tanks through the electrochemical principle of sacrificial anode protection.