Bacteria often live in biofilms, which are dense microbial communities surrounded by a secreted extracellular matrix. Here, we demonstrate that hydrodynamic flow and matrix organization interact to shape competitive dynamics in Pseudomonas aeruginosa biofilms. Irrespective of initial frequency, in competition with matrix mutants, wild type cells always increase in relative abundance in flat-surfaced, straight-tunnel microfluidic devices under simple flow regimes. By contrast, in microenvironments with complex, irregular flow profiles - which are common in natural environments - wild type matrix-producing and isogenic non-producing strains can coexist. This result stems from local obstruction of flow by wild-type matrix producers, which generates regions of near-zero flow speed that favor occupation by cells that do not invest in matrix secretion. Our findings connect the evolutionary stability of matrix production with the hydrodynamics and spatial structure of the surrounding environment, providing a potential explanation for the variation in biofilm matrix secretion observed among bacteria in natural environments.