I'm sorry this is super long. I suck at being concise :.\
It's possible that he's acting up because he loves it. Just because he loves it doesn't mean he's not overstimulated, and that could be even more so if he's excited. It's definitely a tough hurdle, and a big part of the solution will be him growing out of it. Of course, you need some coping strategies in the meantime. Remember that any training will take much longer than you want to become ingrained, and that, even if you can elicit the behavior you want now because he's afraid of being spanked, that only lasts as long as he's afraid. Once he's not afraid, he won't have learned lessons about how to regulate his own behavior. Also, think of spanking this way:
- A child who is afraid is already using up some of his emotional regulation just being afraid.
- Punishing negative behavior does not teach the kid what he should be doing, and he may know what he should not be doing but be at a loss for what else to do.
- Punishing negative behavior--particularly using a method with unusually strong emotional stimuli, like physical pain coming from a beloved authority figure--makes the child focus on the negative behavior. Focusing on negative behavior, even in trying to avoid it, will always be more likely to eventually result in that exact behavior.
That said, my first suggestion to you is to try reacting with as much calmness as possible, because he takes cues from you. The wilder he gets, the calmer you make your body and the quieter you make your voice. This also naturally leads you to sit down, draw him to you, and talk closer into his ear. That also gives him something very clear to focus on, in an environment that may be overwhelming his external and internal senses, and it brings him close to your body and your warmth. It's naturally comforting, because it's similar to a hug and makes him feel more connected to you. From there, your first job is to keep in mind that you're a team. Right now, I think you feel like you're swimming in the ocean and he's a shark. But in fact, from his perspective, he's swimming in the ocean and you're a lifeguard. He says he's sorry on the way home because he really is. Our kids live and die, psychologically, on pleasing us--it's really pretty heartbreaking. But because of being kids, knowing what's the right thing to do is very different from being able to do it, and sometimes the only way they have to tell us what's going on is in a way that we struggle to understand.
You and he both have habits that are going to take a while to break. The more you can control his environment, the easier it will be to begin changing his behavior. Take him into another room or outside to talk about what you want him to do. Make any punishments clear ahead of time, because after a punishment, the window for associating it with the behavior is already closed. Make his environment as predictable as possible, because a predictable, controlled environment allows kids to feel like they have a measure of control over what happens, which is the first step in them choosing the behavior you want.
Finally, 5 is probably-old-enough-but-just-barely to start really talking with him about how to address problems together. Kids love to come up with their own solutions. Now, frankly, his solutions are mostly going to be unworkable to say the least. So you can start by saying--especially ahead of time, that can help a lot--"Now, when we go to this party, we all want to have a good time, and that means we have to work together. I need to know that you will hear me and cooperate with me when I tell you something. So, if I tell you something and you don't hear me, how should we solve that?" At first, he might not even have an idea. If not, give it a nice long moment, and then say, "I think it would help if I hold your hand and get closer to you and then say it again. What do you think?" Leading is not bad here. Then you can say, "Okay, then if I do that, are you willing to look at me and say 'Yes, Mommy'?"
There are lots of these kinds of dialogues available that can help you have a plan for when one of these situations happens, under lots of different names. Try looking for books and YouTube videos about "Positive Parenting" and "Peaceful Parenting". The goal for you is to remember that the kid's behavior does not mean he has the same emotional state that you would if you were acting like that, so you want to empathize with his emotions and motivations while dissociating your emotions from his behavior. Naturally, this also requires you to be patient with yourself. You have to know that it's okay to forgive yourself for mistakes, even if other people are judging you. F*** 'em. You and your kid are the most important people you have a responsibility to, and it might sound selfish, but I promise you, if you prioritize you and your son's happiness, everybody else's experience of you will be more pleasant, not less.