The microbiota comprises the microorganisms that live in close contact with the host, with mutual benefit for both counterparts. The contribution of the gut microbiota to the emergence of castration-resistant prostate cancer (CRPC) has not yet been addressed. We found that androgen deprivation in mice and humans promotes the expansion of defined commensal microbiota that contributes to the onset of castration resistance in mice. Specifically, the intestinal microbial community in mice and patients with CRPC was enriched for species capable of converting androgen precursors into active androgens. Ablation of the gut microbiota by antibiotic therapy delayed the emergence of castration resistance even in immunodeficient mice. Fecal microbiota transplantation (FMT) from CRPC mice and patients rendered mice harboring prostate cancer resistant to castration. In contrast, tumor growth was controlled by FMT from hormone-sensitive prostate cancer patients and Prevotella stercorea administration. These results reveal that the commensal gut microbiota contributes to endocrine resistance in CRPC by providing an alternative source of androgens.