It is well-known that, in a competitive market, the number of firms in a free-entry equilibrium is the efficient one. This paper shows that this textbook result breaks down if firms face demand uncertainty. In this case, entry is excessive relative to the optimum and, therefore, regulation improves market efficiency. This occurs because, in the absence of regulation, entry is motivated by the profits that firms expect to receive if market demand turns out to be high. However, when choosing the optimal regulated entry, the planner also considers that some surplus is lost if demand turns out to be low.