Bacteria regulate many phenotypes via quorum sensing systems. Quorum sensing is typically thought to evolve because the regulated cooperative phenotypes are only beneficial at certain cell densities. However, quorum sensing systems are also threatened by non-cooperative "cheaters" that may exploit quorum-sensing regulated cooperation, which begs the question of how quorum sensing systems are maintained in nature. Here we study the evolution of quorum sensing using an individual-based model that captures the natural ecology and population structuring of microbial communities. We first recapitulate the two existing observations on quorum sensing evolution: density-dependent benefits favor quorum sensing but competition and cheating will destabilize it. We then model quorum sensing in a dense community like a biofilm, which reveals a novel benefit to quorum sensing that is intrinsically evolutionarily stable. In these communities, competing microbial genotypes gradually segregate over time leading to positive correlation between density and genetic similarity between neighboring cells (relatedness). This enables quorum sensing to track genetic relatedness and ensures that costly cooperative traits are only activated once a cell is safely surrounded by clonemates. We hypothesize that under similar natural conditions, the benefits of quorum sensing will not result from an assessment of density but from the ability to infer kinship.