The role of interspecific competition for generating patterns in species' distribution is hotly debated and studies taking into account processes occurring at both large and small spatial scales are almost missing. Theoretically, competition between species with overlapping niches should result in divergence of their niches in sympatry to reduce the costs of competition. Many species show a mosaic distribution within sympatric zones, with the syntopic sites occupied by both species, and allotopic sites where only one species occurs. It is unclear whether such mosaics arise as a consequence of competition-driven niche segregation or due to the decline of their abundances towards range edges driven by environmental gradients. If the interspecific competition matters, we should observe (1) a shift in habitat preferences of one or both species between syntopy and allotopy, and (2) between allopatry and allotopy. Moreover, (3) species should show greater divergence in their habitat preferences in allotopy than in allopatry where (4) no differences in habitat preferences may occur. Finally, (5) shifts should be generally greater in the competitively subordinate species than in the dominant species. We used a unique dataset on abundance of two closely related passerine species, the Common Nightingale (Luscinia megarhynchos) and the Thrush Nightingale (Luscinia luscinia), collected across their syntopy, allotopy and allopatry. The predictions were tested within a generalized mixed-effects modelling framework. After accounting for environmental gradients perpendicular to the species' contact zone, we found a strong support for all but one prediction. Habitat preferences of both species shifted markedly between syntopy and allotopy, as well as between allopatry and allotopy. Whereas the species preferred the same habitats in allopatry, their preferences became strikingly different in allotopy where the abundance of the Common Nightingale increased towards dry and warm sites with low coverage of pastures, while the abundance of the Thrush Nightingale showed exactly opposite trends. Fifth prediction was not supported. Our results indicate that the competition between closely related species can result in considerable changes in habitat use across their geographic ranges accompanied with divergence in their habitat preferences in sympatry. Here, the species "escape" from competition to allotopic sites covered by habitats avoided by the competitor. Therefore, we argue that the interspecific competition is an important driver of species' distribution at both large and small spatial scales.