Power Supply Sees Electromagnet as a Short Circuit
Like many 'output' devices, a coil for producing a magnetic field has a (DC) impedance. This impdance, in combination, with the applied voltage, determines the current, and current and voltage determine the power.

In your case, a 9V DC power and a 0.5 Ohm coil would result in 9/0.5 = 18A current, and 9 * 18 = 162 W power (if your PSU could supply this current, which it can't, as it is rated for 5A). I assume you did not intend to use 162W of power, in which case you have an impedance mismatch: you have a (relatively) high-voltage power, and a (very) low impedance coil. You'll have to change one or the other:


you could use a lower voltage: assuming a safe 4A, your voltage should be 2V.
you could increase the impedance of your coil, by using a smaller diameter wire (with more turns, to compensate for the lower current).
You could use PWM to effectively lower the voltage or increase the impedance (depends on how you look at it), but I would not recommend this: it is much more complex than the transistor-and-relay level electronis that you seem to be more-or-less comfortable with.


PS check Curd's comment, you realy need a base resistor. And you probably need something to absorb the energy in your coil when you switch it off.