Multispecies bacterial populations often inhabit confined and densely packed environments where spatial competition determines the ecological diversity of the community. However, the role of mechanical interactions in shaping the ecology is still poorly understood. Here, we study a model system consisting of two populations of nonmotile Escherichia coli bacteria competing within open, monolayer microchannels. The competitive dynamics is observed to be biphasic: After seeding, either one strain rapidly fixates or both strains orient into spatially stratified, stable communities. We find that mechanical interactions with other cells and local spatial constraints influence the resulting community ecology in unexpected ways, severely limiting the overall diversity of the communities while simultaneously allowing for the establishment of stable, heterogeneous populations of bacteria displaying disparate growth rates. Surprisingly, the populations have a high probability of coexisting even when one strain has a significant growth advantage. A more coccus morphology is shown to provide a selective advantage, but agent-based simulations indicate this is due to hydrodynamic and adhesion effects within the microchannel and not from breaking of the nematic ordering. Our observations are qualitatively reproduced by a simple Pólya urn model, which suggests the generality of our findings for confined population dynamics and highlights the importance of early colonization conditions on the resulting diversity and ecology of bacterial communities. These results provide fundamental insights into the determinants of community diversity in dense confined ecosystems where spatial exclusion is central to competition as in organized biofilms or intestinal crypts.