An individual's choice of habitat should optimize amongst conflicting demands in a way that maximizes its fitness. Habitat selection by one species will often be influenced by presence and abundance of competitors that interact directly and indirectly with each other (such as through shared predators). The optimal habitat choice will thus depend on competition for resources by other species that can also modify predation risk. It may be possible to disentangle these two effects with careful analysis of density‐dependent habitat selection by a focal prey species. We tested this conjecture by calculating habitat isodars (graphs of density assuming ideal habitat selection) of chital deer living in two adjoining dry‐forest habitats in Gir National Park and Sanctuary, western India. The habitats differed only in presence (Sanctuary) and absence (National Park) of domestic prey (cattle and buffalo). Both species are preyed on by Asiatic lions. The habitat isodar revealed at low densities, that chital live in small groups and prefer habitat co‐occupied by livestock that reduce food resources, but also reduce predation risk. At higher densities, chital form larger groups and switch their preference toward risky habitat without livestock. The switch in chital habitat use is consistent with theories predicting that prey species should trade off safety in favor of food as population density increases.