Fecal microbiota transplantation (FMT) is an emerging treatment for recurrent <em>Clostridium difficile</em> infection (RCDI). However, despite its high efficacy and therapeutic potential, the mechanisms underlying FMT are poorly understood. Here, we use whole-genome shotgun sequencing to measure the gut microbiota of 20 RCDI patients and their donors before and after FMT. Surprisingly, although only 30 percent of donor species engraft, engraftment is highly predictable and is largely controlled by mass action and phylogenetic effects. We developed a new strain-tracking algorithm, allowing us to unambiguously detect the transfer of strains from donors to recipients for the first time. We show that, in contrast to species, strains have an all-or-nothing response to FMT and frequently adopt the same configuration in the recipient as in the donor. FMT also facilitates colonization by many environmental strains, but even the frequencies of these seemingly stochastic events are predictable. These findings provide a quantitative framework for donor selection, enabling the engineering of the human microbiota in RCDI patients.