Males are expected to adjust testes investment according to the varying level of sperm competition that they experience. Spatial and temporal variation in population density likely influences sperm competition. In herbivorous aquatic organisms, densities often decrease along a vertical depth gradient, because their food is photosynthetic and thus becomes less abundant in deeper regions where less light penetrates. This decrease should be dramatic on a steep slope, which allows testing of the association between density and testes investment at the within-population level. We tested the effect in the socially monogamous herbivorous cichlid fish Variabilichromis moorii living on a steep slope in Lake Tanganyika. We examined competitor density and food abundance as ecological factors, territory defense behaviors and phenotypic traits (testes investment and somatic investment), and compared them between shallow (4–6 m depth) and deep habitats (10–13 m depth) separated by several dozen meters. We found that food availability drastically decreased with increasing depth and that Vmoorii was much more abundant in shallower habitats. Males in shallower habitats were in better physical condition (based on fat and liver mass) despite experiencing greater costs in terms of territory defense. Testes investment differed in areas with different competitor density and food abundance along a vertical depth gradient, but competitor density was the most explanatory factor of the difference. This suggests that this herbivorous fish would change testes investment in response to population density.