The spin and parity of the $Z_c(3900)^\pm$ state are determined to be $J^P=1^+$ with a statistical significance larger than $7\sigma$ over other quantum numbers in a partial wave analysis of the process $e^+e^-\to \pi^+\pi^-J/\psi$. We use a data sample of 1.92 fb$^{-1}$ accumulated at $\sqrt{s}=4.23$ and 4.26 GeV with the BESIII experiment. When parameterizing the $Z_c(3900)^\pm$ with a Flatte-like formula, we determine its pole mass $M_\textrm{pole}=(3881.2\pm4.2_\textrm{stat}\pm52.7_\textrm{syst})\textrm{MeV}/c^2$ and pole width $\Gamma_\textrm{pole}=(51.8\pm4.6_\textrm{stat}\pm36.0_\textrm{syst})\textrm{MeV}$. We also measure cross sections for the process $e^+e^-\to Z_c(3900)^+\pi^-+c.c.\to J/\psi\pi^+\pi^-$ and determine an upper limit at the 90\% confidence level for the process $e^+e^-\to Z_c(4020)^+\pi^-+c.c.\to J/\psi\pi^+\pi^-$.