If free markets never fail, there's no inherent need for government intervention, though we might object to the resultant wealth distribution on moralistic grounds. But if markets do occasionally fail, then it's possible that government intervention could be used to realign incentives, and "nudge" the market to a higher order equilibrium.
View From An Ivory Tower
Neoclassical economists believe that only a few types of market failures are possible, no matter how often reality disagrees. In particular, neoclassical economists reject the idea that coordination failures can occur. A coordination failure can be roughly described as a scenario where each individual in a group acts in a way that maximizes its own expected outcome, but by doing so fails to maximize the expected outcome of the group. You might ask, how is it possible for everyone to do their best and still reach an outcome that is inferior to some other outcome? The answer is: a failure to coordinate. That is, just because everyone does their best individually does not imply that the group as a whole will do its best collectively. This is a very simple concept with a lot of intuitive appeal. Yet, neoclassical economists reject coordination failures as a possibility, since they argue that if it is profitable for coordination to occur, it will. That also has a lot of intuitive appeal, which is why that theory stuck around for so long. But neoclassical theory doesn't describe the world we live in, which is filled with crooks, liars, and idiots. It describes an idealized world where people can overcome their short-term expectations and desires, collaborating whenever it's profitable, inadvertently advancing the greater, long-term common good.
About As Far As I Can Throw You
There are a variety of real world scenarios where a failure to coordinate can occur. The most basic example is when the parties simply don't trust each other. For example, I would rather pay you to paint my house than paint it myself; and you would rather be paid cash for painting my house than sit around all day. But what I would prefer most of all is to have my house painted for free; and what you would prefer most of all is to get paid for doing nothing. That said, both of us could be better off than we currently are if I paid you to paint my house. However, one of us has to take the risk that the other won't perform. That is, I pay you today and you take the money and run; or you paint my house today and I tell you to piss off when you're done. If either of us expects that the other will not perform, we will not coordinate.
Free market zealots would argue that reputation alone is sufficient to solve this problem. That is, if either of us fails to perform, we will have a bad reputation, and in the future others will not trust us. That would probably work in a tiny village where everyone knows everyone else, travel is infrequent, and therefore reputations are easy to track. But in the developed world, it's impractical and creates a fantastic opportunity for those willing to move around a lot pretending to be a painter. Moreover, even if it were practical, any system based on reputation alone would favor incumbents and make it very difficult for new entrants to compete, since no one wants to be the first to find out that their painter is actually a career swindler. So what's the solution? Enforceable contracts. That is, the government, which has all kinds of power over its citizens, can force you to perform under your agreements. In this respect, the existence of government solves a basic coordination problem by supplanting bilateral trust. But this mechanism doesn't completely eliminate the issue of trust, it just substitutes the mutual trust of the parties with their trust in the government. That is, I will trust that my contract is valid and enforceable insofar as I believe in the government's ability and willingness to enforce it. This whole government substitution process can be viewed as a variation on the reputation game. But in the context of governments enforcing contracts, keeping track of reputation becomes practical, since it's fairly easy to keep track of the enforcement records of a handful of governments. As such, enforcing contracts is, in my opinion, a necessary form of government intervention into otherwise free markets.