AbstractPlasmids are autonomous genetic elements that can be exchanged between microorganisms via horizontal gene transfer (HGT). Despite the central role they play in antibiotic resistance and modern biotechnology, our understanding of plasmids’ natural ecology is limited. Recent experiments have shown that plasmids can spread even when they are a burden to the cell, suggesting that natural plasmids may exist as parasites. Here, we use mathematical modeling to explore the ecology of such parasitic plasmids. We first develop models of single plasmids and find that a plasmid’s population dynamics and optimal infection strategy are strongly determined by the plasmid’s HGT mechanism. We then analyze models of co-infecting plasmids and show that parasitic plasmids are prone to a “tragedy of the commons” in which runaway plasmid invasion severely reduces host fitness. We propose that this tragedy of the commons is averted by selection between competing populations and demonstrate this effect in a metapopulation model. We derive predicted distributions of unique plasmid types in genomes—comparison to the distribution of plasmids in a collection of 17,725 genomes supports a model of parasitic plasmids with positive plasmid–plasmid interactions that ameliorate plasmid fitness costs or promote the invasion of new plasmids.