Logic level P-channel Mosfet switch
There are two things wrong with your circuit: -


The P channel FET is upside down (will always conduct thru its body diode)
If you correctly placed the FET it's a little tricky to directly drive it from a 3v3 logic power supply without damage. You need level translation.


The easiest method is to use an N channel device with the load tied to the 24V rail. Here's an idea that controls a motor: -



If you need the load to be grounded you need an extra transistor: -



Note that there is some attention to protecting the gate from over-voltage - the two resistors and the zener diode limit the gate voltage to below the maximum allowed by the P channel FET.

If your MOSFET was a logic level device that adequately operated at 3V3 gate drive you could use a zener diode directly from the 3V3 logic but it can be a little tricky to set up correctly.