Remove the gate from the posts. This will allow you to work on the gate without it swinging.
Examine the hinges and hinge screws. Remove any of the screws or hinges that are loose and replace them with new ones. If the screws look like they are too short for the hinge, use longer ones.
Reposition the hinges. Look the hinge placement. Sometimes the hinge is placed on an area of a gate that allows the weight of the gate to pull down on it, making it bend or loosen. Place the hinges closer to the center of the post. You will need to drill new holes in order to do this.
Add another hinge. You can add another hinge to the center of the gate post if you need extra strength. Contact a local hardware store and see if they can order an identical hinge to the one you have.
Replace the post. If the post is wood, it could be rotting, causing the gate to sag. Pull the post out and put in a new one. Attach the gate to the new post.