NPN transistor for switching electromagnetic relay
Add a flyback diode. When the relay gets turned off the coil acts as an inductor which creates a voltage spike.

Adding a diode will let the coil dissipate the stored energy in something other than the transistor.






simulate this circuit &ndash; Schematic created using CircuitLab