A fundamental problem in biology is the evolutionary transition from single cells to multicellular life forms. During this transition the unit of selection shifts from individual cells to groups of cooperating cells. Although there is much theory, there are few empirical studies. Here we describe an evolutionary transition that occurs in experimental populations of Pseudomonas fluorescens propagated in a spatially heterogeneous environment. Cooperating groups are formed by over-production of an adhesive polymer, which causes the interests of individuals to align with those of the group. The costs and benefits of cooperation, plus evolutionary susceptibility to defecting genotypes, were analysed to determine conformation to theory. Cooperation was costly to individuals, but beneficial to the group. Defecting genotypes evolved in populations founded by the cooperating type and were fitter in the presence of this type than in its absence. In the short term, defectors sabotaged the viability of the group; but these findings nevertheless show that transitions to higher orders of complexity are readily achievable, provide insights into the selective conditions, and facilitate experimental analysis of the evolution of individuality.