Resource availability may determine local breeding systems and may also vary locally between different habitats, affecting the way individuals distribute themselves between these habitats. For nest-breeding fishes, nest site availability is a crucial resource that has been found to affect local sexual selection regimes and thus breeding systems. In this study, we compared the availability and size distribution of nest sites and their consequences for habitat preference, fish distributions and the breeding system in sand gobies (Pomatoschistus minutus) breeding in two different habitats. The usual breeding sites of sand gobies are shallow sandy beaches, but here we report their breeding in a novel environment, on rocky bottoms. We found obvious differences between the two habitats. The density of occupied nests was nearly 50 times higher in rock habitat than on sand bottoms. However, competition for nest sites was stronger on sand; nearly all natural nest sites found were in use and empty nest sites were occupied at a much higher rate on sand than in rock habitat. In addition to the numerical differences, nests were larger and contained more eggs in rock habitat than in sand habitat. Moreover, we found significant habitat-specific differences in fish size distribution. The intensity of intrasexual competition as a result of the degree of nest site availability explains the observed patterns within the habitats, but not between them. These habitat-related differences are better explained by the larger average size of nests on rocky bottoms. The effect of nest size on habitat preference was confirmed experimentally by laboratory experiments. When nest size did not differ between the habitats, gobies originating in the two environments showed an equal preference for the sand habitat.