As a keeper of birds, getting bitten kind of comes with the territory, like being stung as a bee keeper. You do not WANT to be stung/bitten, but it is the risk you take when you choose to closely associate with animals that can hurt when threatened.
The key is to practice good husbandry and learn from past mistakes. Sometimes it is unavoidable, like if you are bitten while administering medicine or rescuing a bird from a dangerous situation. Other times it IS avoidable, but require attentiveness and a willingness to adapt your handling techniques to meet the needs of your parrot.
You don't want to get bitten and, if you have a good relationship with your parrot, he probably doesn't want to bite you. But if you leave him no other option ... he will do what he has to do. I would guess that your hand scared him and he wanted it to go away. Many parrots see their cage as a "safe zone" and don't appreciate humans messing around in their area.
If you haven't had the bird long, I would give him some space and work on building trust. Let him feel safe in his cage and try not to provoke more attacks, since biting can become a habitual response if you are not careful.