LEDs keep dying in 12v circuit with powerful electromagnet
Do you have a catch diode across the electro magnet to clamp the high voltage pulse that it will create when you remove power?  If not, this is your issue.  The high voltage pulse will be at least 2x the supply voltage, and can be much higher, reverse biased across the LED.  LEDs are not designed to stand off such a voltage, and thus it fails.



simulate this circuit &ndash; Schematic created using CircuitLab
Based on some of the other comments and answers, just wanted to clarify that catch diode, flyback diode, and free wheeling diode are all interchangeable terms for the same thing in this case.