The correct answer was already given, but if I may put a fine point on it: your mistake started when you left the house without carrying pepper spray (readily accessible by your weak hand if you don't need to untuck cover garments to draw and fire in under 1.5 seconds, otherwise in your strong hand) as part of your edc kit.
If you're going to draw something to attempt to put a stop to an aggressor, whether it's just 1 or half a dozen dudes, drawing pepper spray and being intent on using it is precisely the right balance of deterrence and lawful escalation (since it does no more than even the odds).
If they continue to escalate (as in, continue to step closer despite knowing the consequences), just use it and take the first step of going to your concealed weapon, and if your life remains in danger, drop the spray, draw and fire with no regrets. (If you're the aggressor and you also draw pepper spray against someone who is armed, you deserve literally whatever you get, including a bullet to the frontal lobe. Pro-tip: don't be the aggressor.)
In all cases, definitely attempt to back off, if possible: make them chase you. And, a very calm and clear "please stop" will be more psychologically effective than an incoherently screamed command.
Practice drawing to and shooting from a retention position with a locked weak arm out (so you don't shoot yourself in the hand if you ever need to do that in real life). If you must, look at center axis relock, do it a bit to feel like John Wick for a few moments of your life, then probably forget about it.
Also, join IDPA/USPSA and actually enter into it: it won't make you a more effective defensive shooter (you need legitimate training, not just advice from the internet), but it will make you a better gun handler and more comfortable.