The debate on the immigration policies in OECD countries has turned its attention towards illegal migrants. Given that migration flows are determined by immigration laws, the probability of potential detection, penalties for unauthorised migrants and their employers, and on income differences between sending and receiving countries, this paper presents a new approach to the problem of illegal migration, grounded on the economic theory of illegal behaviour. The framework considers the interaction of potential migrants, citizens, employers, and the government. After introducing the supply function of illegal migration and its determinants, the trade-off between social costs and benefits of preventing and combating illegal migration is demonstrated. This trade-off results in an optimal level of migration larger than zero. A complete market model of illegal migration is offered by presentation of a demand curve of illegal migration, based on the tolerance of the society towards clandestine foreigners. Equilibrium forces predict a non-zero level of illegal migration. The rule of law of our legal systems, according to which any illegal activity has to be reduced to zero, bears the danger of producing inefficient disequilibria. A reasonable policy of wanted and unwanted migration should address the question of how to allocate scarce resources. Ignoring social optima and equilibrium forces means to abandon public resources that could be used for other public assignments, such as schooling, or foreign aid, for instance, i.e., measures that could strike the problem of illegal migration at its root.