The transistor is one of the most influential inventions of modern times and is ubiquitous in present-day technologies. In the continuing development of increasingly powerful computers as well as alternative technologies based on the prospects of quantum information processing, switching and amplification functionalities are being sought in ultrasmall objects, such as nanotubes, molecules or atoms1, 2, 3, 4, 5, 6, 7, 8, 9. Among the possible choices of signal carriers, photons are particularly attractive because of their robustness against decoherence, but their control at the nanometre scale poses a significant challenge as conventional nonlinear materials become ineffective. To remedy this shortcoming, resonances in optical emitters can be exploited, and atomic ensembles have been successfully used to mediate weak light beams7. However, single-emitter manipulation of photonic signals has remained elusive and has only been studied in high-finesse microcavities10, 11, 12, 13 or waveguides8, 14. Here we demonstrate that a single dye molecule can operate as an optical transistor and coherently attenuate or amplify a tightly focused laser beam, depending on the power of a second 'gating' beam that controls the degree of population inversion. Such a quantum optical transistor has also the potential for manipulating non-classical light fields down to the single-photon level. We discuss some of the hurdles along the road towards practical implementations, and their possible solutions.