We have developed an individual-based model to reflect the complexity of the early phase of drug resistance selection in a nematode/sheep model. The infection process consists of the stochastic ingestion of infective larvae spatially aggregated in clumps. Each clump corresponds to infective larvae, which are the offspring of the mature nematodes from a given sheep. We studied the dynamics of the parasitic population and the frequency of the recessive resistance alleles during selection by anthelmintic treatments. The interaction between genetic and demographic processes illustrated the trade-off between the control of the infection and the delay of resistance selection. We confirmed the importance of the number of treatments and their timing. The same treatment frequency may result in different outcomes on resistance selection in relation to the size of the refuge (infective larvae on pasture). Treatment applied during the summer (when the mortality of infective larvae on pasture was high), may lead to a rapid selection of drug resistance and a lack of control of sheep and pasture contamination. We showed that higher stocking rates were also a force in promoting the resistance allele selection.