The circuit should work but the LM358 isn't very good when working from low voltages, using a real comparator would help.
The PWM amplitude will be halved by the divider of R1/R2 so if you are feeding a 5V PWM signal it will never go higher than 2.5V and for example, at 50% PWM ratio will only be 1.25V. Adjusting P1 sets the voltage at which the output at pin 1 should switch state, when the voltage at pin 3 goes higher than the voltage at pin 2, pin 1 should go high and turn the relay on.
I suspect your problem is you are using an op-amp that doesn't work very well at low voltages, you should really use a comparator instead as they are designed to switch abruptly instead of passing through a linear region.
Brian.