Good question. People who are scrupulous probably think of questions like this too. They try to break sin down into technicalities and therein, create more problems then perhaps they originally had.
There have been times where I was tempted to masturbate and did not do it, or started to do it but stopped, or wasn’t doing it manually and wondered whether that counts, or it was all mental and not physical, but an erection and ejaculation was purposely achieved. I’d also question how accountable I am in that I have a fetish or two and flashes or images cannot necessarily be controlled as they come in uninvited and unannounced.
In each case, I was able to devise a reason, a cop out, or a cheat that, in my mind, would not justify the action, but would at least explain it away and allow me to not feel so sorry for myself about it. And these created more problems and sin was able to prevail because of it.
Look at it this way: if you have to ask questions, even specific questions, about what’s ok and what’s not and what if this happened before that and this and that but not this happened, and you create scenarios and such just to answer a simple question about catholic morality which is very clear, then you’ve been caught in the web of the enemy. While you are able to struggle with it morally (a good thing) the web latches to you and keeps you from escaping fully. The devil is that spider that is eventually going to make his way down there and eat you. He takes his time, just like the spider, because he realizes you’re trapped and there’s no hurry for him. He’s got a life-time to tempt you and if he sees you’re making excuses for yourself and trying to lie to yourself about grave matter in order to feel like you did nothing wrong, then all the more reason for him to take his time. In fact, you’re doing his job for him in that case.
I’d be a hypocrite if I said I haven’t been in that situation before, or that I am not tempted daily either to masturbate or to entertain an impure thought. In my case, it cannot be avoided, due to a fetish I have, but I do what I can to avoid acting on it or entertaining the thoughts so long as they are not sexual in nature. We all go through this and it’s part of the struggle of being a good Christian. The devil knows your weak points, so he’s going to attack those.
To answer your question from my opinion, and not that of the catholic church’s stand, I would say it was a mortal sin. Ejaculation or not, you masturbated. Masturbation is not an act that is defined by it’s completion only, just as sexual intercourse is not. You don’t have to ‘finish’ in order for it to be a problem. If you cheat on your wife, but it’s only an emotional affair, it’s still cheating on your wife.
I do sympathize with you, though, I really do, as I’ve been there and done that. Know that God loves you, and while in the example you gave, you will have committed a mortal sin that requires confession, there is some merit in that you at least resisted and stopped. That voice that pleaded for you to stop was either the Holy Spirit or your guardian angel. So, to me, this is a sign that God is wanting to help you fight this, but you have to be open to accepting that help and do what is required.