Recent theory suggests that a mix of lottery and niche processes can facilitate coexistence between competing species, but this has not yet been empirically tested. Previous research has suggested that a competitive lottery for space promotes coexistence between two ecologically similar species, Gobiodon histrio and Gobiodon erythrospilus. However, not all the assumptions of lottery competition have been tested, and patterns of habitat use by adults suggest niche partitioning. Here, we investigated the hypothesis that the mechanism of competition changes with ontogeny, with a lottery for space operating at settlement and niche partitioning occurring in adults. Patterns of resource use in the field were compared for juveniles and adults of the two species. Pelagic larval duration (PLD) and size-at-settlement was also estimated to determine if size differences at settlement could affect the outcome of competitive interactions among juveniles. Habitat preference and size-based competitive ability were then tested for juveniles and adults in laboratory experiments. Finally, a transplant experiment was performed to test the fitness-associated consequences of niche partitioning among adults and its implications for coexistence of the two species. G. histrio had a similar PLD (20.7 ± 2.0 days) to G. erythrospilus (18.5 ± 1.9 days), and there was no difference in size-at-settlement between the species. Juveniles of the two species had similar patterns of habitat use and similar competitive abilities, supporting the lottery mechanism at settlement. However, adults differ in their habitat use, supporting the prediction that resource partitioning increases with ontogeny. In laboratory experiments, adults of each species preferred colonies of Acropora nasuta. However, G. histrio was a superior competitor and prevented G. erythrospilus from using A. nasuta in > 70% of the trials. In the field transplant experiment, G. erythrospilus (inferior competitor) suffered less of a fitness loss when occupying the non-preferred coral (A. spathulata) compared with G. histrio, which could explain its ability to persist when displaced by the superior competitor. These results suggest that the competitive mechanism operating between the two Gobiodon species shifts from a lottery for space to niche partitioning through ontogeny, and that these two mechanisms of competitive coexistence are not mutually exclusive.