As mentioned earlier, prevent and deter can sometimes mean the same thing.
Deter is often used when the other party has a choice. It generally implies threatening to take an action in response.
The police can deter a bad person from breaking the law. (The police are threatening to put someone in jail / hurt them.)
Nuclear deterrence is based on mutually assured destruction. (You are deterring a country from using a nuclear weapon.)
Prevent can be used more generally -- the thing that is happening may not be a person or organization. Prevention implies preparation.
The goalie's job is to prevent the ball from going in the goal. (You can't deter a ball.)
Locking your doors can prevent crime.
Using a spellchecker can prevent typing mistakes.
Wearing a condom can prevent disease transmission.