Semiconductor p-n junctions are essential building blocks for electronic and optoelectronic devices. In conventional p-n junctions, regions depleted of free charge carriers form on either side of the junction, generating built-in potentials associated with uncompensated dopant atoms. Carrier transport across the junction occurs by diffusion and drift processes influenced by the spatial extent of this depletion region. With the advent of atomically thin van der Waals materials and their heterostructures, it is now possible to realize a p-n junction at the ultimate thickness limit. Van der Waals junctions composed of p- and n-type semiconductors--each just one unit cell thick--are predicted to exhibit completely different charge transport characteristics than bulk heterojunctions. Here, we report the characterization of the electronic and optoelectronic properties of atomically thin p-n heterojunctions fabricated using van der Waals assembly of transition-metal dichalcogenides. We observe gate-tunable diode-like current rectification and a photovoltaic response across the p-n interface. We find that the tunnelling-assisted interlayer recombination of the majority carriers is responsible for the tunability of the electronic and optoelectronic processes. Sandwiching an atomic p-n junction between graphene layers enhances the collection of the photoexcited carriers. The atomically scaled van der Waals p-n heterostructures presented here constitute the ultimate functional unit for nanoscale electronic and optoelectronic devices.