Some simple steps to deal with aggression in young children are:
1. Stop the behavior immediately in a calm voice
2. Use eye contact when explaining (in few words) that it is not nice to hit or hurt others
3. Don't ask questions in the moment to understand why
4. Have the child take a time out immediately
5. Make your child apologize and/or do something nice to make up for their behavior
After the situation is over, you can discuss further but be firm that it is never appropriat to hurt others. Analyze the triggers for the sitution and try to head it off in the future when possible. With young kids it is especially beneficial to practice or re-enact the situation again so they know how they should have responded and how they should handle it in the future.