I would check your fuses anytime there's an electrical problem, But the fact that it attempts to close at all means its probably not the fuse.
I don't know if the motor is 2 pin or 3 pin, if you have a service manual you could check.
2pin means more than likely switch.
3pin could be switch or a bad wire/connection.
Some sun/moonroofs have a stopper switch to prevent you from pushing the motor into a closed roof, which could also be bad.
These are just general speculation, I'm not certain on the specific setup in a ZJ