First, government protects us from private-involuntary associations. Through law, it attaches artificial side effects to private actions constituting such associations, thus making them less attractive options. Drunk driving carries the risk of accident, injury, property loss, and death. Government increases the risks by threatening fines, imprisonment, and license revocation. The existence of law presumes that people are less likely to commit murder if the side effect of such will be the electric chair.
Law can also be regarded as a price system calculated to run private-involuntary associations off the "market" by making them too "expensive".
Of course, laws are not entirely successful. Sanctions provided for violators may be inadequate to discourage the prohibited action—mere "slaps on the wrist". If the chance that a sanction will actually be imposed is low, people may discount its severity by its improbability. Indeed, increasing the required sanction for breaking a law may reduce the likelihood it will ever be imposed: electrocution deters no jaywalkers if juries refuse to convict flagrant violators because they find the punishment excessive.
No legal system can eliminate all crime. The only way to put a complete end to crime would be to repeal all laws, a "solution" which does not have much appeal. Thus government's function is not to eliminate private-involuntary associations but to minimize them. While repealing all laws would be counterproductive, "decriminalizing" some actions may be desirable if costs of outlawing them outweigh the benefits. As St. Thomas Aquinas noted many centuries ago, it is impossible for government to outlaw all sins1. Government should not spread its limited enforcement capabilities too thin, neglecting to enforce more important laws while prosecuting less important ones. "Decriminalization" is most frequently discussed in the context of personal drug use, sexual activity, and so forth, which supposedly concern only the "consenting adults" involved.