The piezoelectric characteristics of nanowires, thin films and bulk crystals have been closely studied for potential applications in sensors, transducers, energy conversion and electronics. With their high crystallinity and ability to withstand enormous strain, two-dimensional materials are of great interest as high-performance piezoelectric materials. Monolayer MoS2 is predicted to be strongly piezoelectric, an effect that disappears in the bulk owing to the opposite orientations of adjacent atomic layers. Here we report the first experimental study of the piezoelectric properties of two-dimensional MoS2 and show that cyclic stretching and releasing of thin MoS2 flakes with an odd number of atomic layers produces oscillating piezoelectric voltage and current outputs, whereas no output is observed for flakes with an even number of layers. A single monolayer flake strained by 0.53% generates a peak output of 15mV and 20pA, corresponding to a power density of 2mWm(-2) and a 5.08% mechanical-to-electrical energy conversion efficiency. In agreement with theoretical predictions, the output increases with decreasing thickness and reverses sign when the strain direction is rotated by 90°. Transport measurements show a strong piezotronic effect in single-layer MoS2, but not in bilayer and bulk MoS2. The coupling between piezoelectricity and semiconducting properties in two-dimensional nanomaterials may enable the development of applications in powering nanodevices, adaptive bioprobes and tunable/stretchable electronics/optoelectronics.