Poly(3,4-ethylenedioxythiophene) blended with polystyrenesulfonate and poly(styrenesulfonic acid), PEDOT:PSS, has found widespread use in organic electronics. Although PEDOT:PSS is commonly used in its doped electrically conducting state, the ability to efficiently convert PEDOT:PSS to its undoped nonconducting state is of interest for a wide variety of applications ranging from biosensors to organic neuromorphic devices. Exposure to aliphatic monoamines, acting as an electron donor and Brønsted-Lowry base, has been reported to be partly successful, but monoamines are unable to fully dedope PEDOT:PSS. Remarkably, some - but not all - polyamines can dedope PEDOT:PSS very efficiently to very low conductivity levels, but the exact chemical mechanism involved is not understood. Here, we study the dedoping efficacy of 21 different aliphatic amines. We identify the presence of two or more primary amines, which can participate in an intramolecular reaction, as the key structural motif that endows polyamines with high PEDOT:PSS dedoping strength. A multistep reaction mechanism, involving sequential electron transfer and deprotonation steps, is proposed that consistently explains the experimental results. Finally, we provide a simple method to convert the commonly used aqueous PEDOT:PSS dispersion into a precursor formulation that forms fully dedoped PEDOT:PSS films after spin coating and subsequent thermal annealing.