Endocrine therapies for prostate cancer inhibit the androgen receptor (AR) transcription factor. In most cases, AR activity resumes during therapy and drives progression to castration-resistant prostate cancer (CRPC). However, therapy can also promote lineage plasticity and select for AR-independent phenotypes that are uniformly lethal. Here, we demonstrate the stem cell transcription factor Krüppel-like factor 5 (KLF5) is low or absent in prostate cancers prior to endocrine therapy, but induced in a subset of CRPC, including CRPC displaying lineage plasticity. KLF5 and AR physically interact on chromatin and drive opposing transcriptional programs, with KLF5 promoting cellular migration, anchorage-independent growth, and basal epithelial cell phenotypes. We identify ERBB2 as a point of transcriptional convergence displaying activation by KLF5 and repression by AR. ERBB2 inhibitors preferentially block KLF5-driven oncogenic phenotypes. These findings implicate KLF5 as an oncogene that can be upregulated in CRPC to oppose AR activities and promote lineage plasticity.