The strand-exchange reaction is central to homologous recombination. It is catalysed by the RecA family of ATPases, which form a helical filament with single-stranded DNA (ssDNA) and ATP. This filament binds to a donor double-stranded DNA (dsDNA) to form synaptic filaments, which search for homology and then catalyse the exchange of the complementary strand, forming either a new heteroduplex or-if homology is limited-a D-loop1,2. How synaptic filaments form, search for homology and catalyse strand exchange is poorly understood. Here we report the cryo-electron microscopy analysis of synaptic mini-filaments with both non-complementary and partially complementary dsDNA, and structures of RecA-D-loop complexes containing a 10- or a 12-base-pair heteroduplex. The C-terminal domain of RecA binds to dsDNA and directs it to the RecA L2 loop, which inserts into and opens up the duplex. The opening propagates through RecA sequestering the homologous strand at a secondary DNA-binding site, which frees the complementary strand to sample pairing with the ssDNA. At each RecA step, there is a roughly 20% probability that duplex opening will terminate and the as-yet-unopened dsDNA portion will bind to another C-terminal domain. Homology suppresses this process, through the cooperation of heteroduplex pairing with the binding of ssDNA to the secondary site, to extend dsDNA opening. This mechanism locally limits the length of ssDNA sampled for pairing if homology is not encountered, and could allow for the formation of multiple, widely separated synapses on the donor dsDNA, which would increase the likelihood of encountering homology. These findings provide key mechanistic insights into homologous recombination.