Biofilms are social entities where bacteria live in tightly packed agglomerations, surrounded by self-secreted exopolymers. Since production of exopolymers is costly and potentially exploitable by non-producers, mechanisms that prevent invasion of non-producing mutants are hypothesized. Here we study long-term dynamics and evolution in Bacillus subtilis biofilm populations consisting of wild-type (WT) matrix producers and mutant non-producers. We show that non-producers initially fail to incorporate into biofilms formed by the WT cells, resulting in 100-fold lower final frequency compared to the WT. However, this is modulated in a long-term scenario, as non-producers evolve the ability to better incorporate into biofilms, thereby slightly decreasing the productivity of the whole population. Detailed molecular analysis reveals that the unexpected shift in the initially stable biofilm is coupled with newly evolved phage-mediated interference competition. Our work therefore demonstrates how collective behaviour can be disrupted as a result of rapid adaptation through mobile genetic elements.