keep holding him. tell him you will help keep him safe until he can keep himself safe. maybe try letting him go and see if he stays next to you and calms down. If so, that's fine, just hang out with him and tell him you're ready to hug him when he's ready to get a hug. If he's violent at all then bear hug him until he calms down. It's not always a quick thing--he's having big feelings. I tell my children "I am bigger than your big feelings. I will keep you safe. I love you even when you don't feel lovable." things like that.
It might also help to back up when he *starts* getting upset and give him another chance to do it himself without help. One of my children realizes that he's waited too long and feels like he's failed and the greatest act of grace I can offer him is to give him one more chance to be successful. Since that is the goal anyway, I don't mind at all