Realistically, you can't. Your son is four. A four year old doesn't have the brain development for conflict resolution entailing the use of carefully applied physical force.
Your son doesn't need to learn how to physically defend himself at this age, or learn to physically deter aggressors. He needs to learn that he can trust the adults charged with his care to intervene on his behalf when situations are beyond his ability to handle.
You're in the immediate vicinity, observing these situations. When you see it happen, you should be protecting your son. You have no way of knowing how far it will escalate. Some light pushing or hitting can be normal for young children, but outright aggression can be unpredictable. It's your responsibility to intercede and prevent your son from receiving or causing physical harm.
After checking your son to make sure he's okay, physically and emotionally, you should explain to him that what the other child did was not okay. If no adult is saying anything to the children while these things are happening, then he's going to assume that getting pushed around or pushing people around is the status quo. Instead, he needs to learn that it's aberrant, unacceptable behavior that won't be tolerated, even if he can't defend himself.
You may also address the other child directly. You can tell them it's not okay to hit people, or your son. This should be said in a calm, collected manner without any hint of hostility. Nothing more needs to be said. The kid will get the picture.
By actually approaching your son, you may signal to the other child, or their parent(s), that what has happened was not okay. The other parent may be mortified and resolve the situation by addressing their child directly, which could lead to a more beneficial resolution: the aggressive child being disciplined for their misbehavior.
You may run into parents that get defensive or hostile if you get near their child. Typically, a calm, peaceful demeanor smooths things over. It's hard for a hostile or argumentative person to seem that they're in the right, even to themselves, when the other person stays entirely level-headed and reasonable.
Trying to teach your son to handle it physically isn't the solution, as you've seen. In your example, your son turned into the aggressor. He could have then hurt the other child, leaving you (and your son) legally liable for the any harm. The situation could have gone the other way: the other boy could have been more adept at fighting, and taken your son's retaliation as a reason to escalate. Your son may have gone from receiving mere emotional bruising to being the victim of a pummeling himself.
If you want your son to learn to handle these situations with physical responses, that's your prerogative. However, I would urge you to wait a few years before putting that burden on him. Right now he needs to have his trust reinforced, and see examples of positive, effective, non-violent conflict resolution.