Semiconductor heterostructures form the cornerstone of many electronic and optoelectronic devices and are traditionally fabricated using epitaxial growth techniques. More recently, heterostructures have also been obtained by vertical stacking of two-dimensional crystals, such as graphene and related two-dimensional materials. These layered designer materials are held together by van der Waals forces and contain atomically sharp interfaces. Here, we report on a type-II van der Waals heterojunction made of molybdenum disulfide and tungsten diselenide monolayers. The junction is electrically tunable, and under appropriate gate bias an atomically thin diode is realized. Upon optical illumination, charge transfer occurs across the planar interface and the device exhibits a photovoltaic effect. Advances in large-scale production of two-dimensional crystals could thus lead to a new photovoltaic solar technology.