We propose a theoretical framework for the relationship between animal welfare and the economic performance of livestock farms. We empirically analyse this relationship based on a unique dataset of randomly sampled Danish pig herds that includes information from unannounced inspections of the compliance with the animal welfare legislation. We find large variations in economic performance and animal welfare. The relationship between these two indicators is rather weak, but tends to be slightly positive. A possible explanation for our results is that management has a major influence on both economic performance and animal welfare so that good farm managers are able to meet all animal welfare regulations, while achieving a high economic performance.