No it doesn't count as failing. You stopped the urge! Sure it would have been better if you stopped the urge before you M'd at all but that's not what happened. You were about to be fully consumed but you stopped! Now you identified that you didn't want to M so just work on dismissing the urges before they materialize at all.