Welcome to your child having a mind of his own, but not so much in terms of empathy. This will be the next several years of your life, to some extent.
The best thing to do in my experience is to let him know that he's hurt you, and that if he does it again you'll have to put him down for a minute so that he doesn't keep hitting you. It won't always help - it will likely turn into a game, to some extent - but that's largely unavoidable. Yelling at him, grabbing his hand, hitting him back even lightly are all bad ideas - they tell him that violence or physical power is acceptable, which is precisely the opposite of what you're aiming for here. He also doesn't understand "wrong" at this point in his life; he needs to understand why it's wrong, hence focusing on the pain he caused you.
He won't fully understand what it means that you are sad, but that's the important message here. This is very similar to biting, which also is common at around 1-2 years old; a firm but not angry "No thank you, that hurts Mommy and makes me sad. Please don't do that again or I will have to put you down so you can't hurt me."
You can also try for "Hitting isn't nice, petting and hugging is nice but not hitting" redirection; I haven't had as much success with that, but it seems reasonable. That's similar to "Teeth are not for biting, they're for chewing, would you like a teether?" which did work well for us with our children (who were both to some extent biters).
There are some books that might also help; "Teeth are not for biting" is a classic, which has a corresponding "Hands are not for hitting".