We're active in rescue. For almost nine years, we've fostered one male after another. We don't foster puppies because of our work schedule and we don't foster females because our two girls rule.
Some fosters have been model citizens with impeccable manners. Others have spent little or no time in a house and don't understand how to climb stairs, aren't housetrained, are mouthy, jump up, countersurf, etc etc.
Training these dogs involves a combination of stick and carrot. I use different approaches, depending on the dog. Strictly positive training is wonderful for puppies. Not so wonderful for a knuckle-headed young male who's full of himself, in my experience.
You did the right thing. You didn't strike him. You spoke to him in a loud, firm voice

And that is obviously what the dog needed, based on his change in behavior.