Proper configuration of a PWM fan which should be stopped when the controller power is cut off
Have a look at the below corrected diagram .                            1). You should add a freewheeling diode at the motor terminal to catter inductive kicks.                                                                2)If you need further protection you can isolate the microcontroller section from the MOSFET via an optocoupler, and there power supplies respectively.     3) Add a zener at the base of the Mosfet to protect the gate at what ever, voltage you are operating the FET.You may also try adding an inverter stage to switch off the FET on power off.  @Ivan  ,I missed your datasheet anyways, Try using an inverter in between D3 and rest of the ckt of yours. Sometyhing like this;