Government has a role two ways.
First, in ensuring markets work efficiently and smoothly. This often entails enacting laws that increases the dissimenation of information so that individuals can make better choices. In Econ 101, you learn that the laws of supply and demand you assume all participants have perfect knowledge. That isn't the case. So not only do laws increasing transperancy in markets push the price of a good to a natural clearing price, but also increases the utility of individuals. A simple example is requiring food companies to display nutritional contents on their products, or full-disclosure laws for companies wishing to sell stock on publicly traded stock exchanges. This also includes anti-trust laws. Most industries do not tend towards monopoly, especially in the long-run. But it can happen occassionally in the short-term. Laws preventing monopolization ensures that entities aren't able to extract economic rents from the economy.
Second, to internalize costs that society deem too important to be left to the market, or when markets fail. People often think of healthcare or social programs in this manner, but it also includes other services people naturally associate with government, such as the army or the police. There will always be some who are left behind in the market economy for whatever reason. As a society gets richer, it is more willing to spread the costs around to protect those who are left behind. An example where markets fail is in education since markets aren't particularly good as assessing the costs one should incur for primary education. In theory, one should be willing to pay for an education based on the future earnings stream provided by that education. However, most people don't know what they want to be when they're 5 years old - unless you count "cowboy" or "princess" as serious occupations. So society pays for education because not only can some not afford to pay for education, but because it impossible to assign a cost based on future income at that age. As people get older, and are more apt to know what it is they want to do for a living, they can shoulder more of the cost of their education, i.e. at University.