Widely used solid-state devices fabricated with inorganic semiconductors, including light-emitting diodes and solar cells, derive much of their function from the p-n junction. Such junctions lead to diode characteristics and are attained when p-doped and n-doped materials come into contact with each other. Achieving bilayer p-n junctions with semiconducting polymers has been hindered by difficulties in the deposition of thin films with independent p-doped and n-doped layers. Here we report on how to achieve permanently fixed organic p-n heterojunctions by using a cationic conjugated polyelectrolyte with fluoride counteranions and an underlayer composed of a neutral conjugated polymer bearing anion-trapping functional groups. Application of a bias leads to charge injection and fluoride migration into the neutral layer, where irreversible covalent bond formation takes place. After the initial charging and doping, one obtains devices with no delay in the turn on of light-emitting electrochemical behaviour and excellent current rectification. Such devices highlight how mobile ions in organic media can open opportunities to realize device structures in ways that do not have analogies in the world of silicon and promise new opportunities for integrating organic materials within technologies now dominated by inorganic semiconductors.