Electronic transport through nanostructures is greatly affected by the presence of superconducting leads1, 2, 3. If the interface between the nanostructure and the superconductors is sufficiently transparent, a dissipationless current (supercurrent) can flow through the device owing to the Josephson effect4, 5. A Josephson coupling, as measured by the zero-resistance supercurrent, has been obtained using tunnel barriers, superconducting constrictions, normal metals and semiconductors. The coupling mechanisms vary from tunnelling to Andreev reflection5, 6, 7, 8. The latter process has hitherto been observed only in normal-type systems with a continuous density of electronic states. Here we investigate a supercurrent flowing through a discrete density of states—that is, the quantized single particle energy states of a quantum dot9, or 'artificial atom', placed between superconducting electrodes. For this purpose, we exploit the quantum properties of finite-sized carbon nanotubes10. By means of a gate electrode, successive discrete energy states are tuned on- and off-resonance with the Fermi energy in the superconducting leads, resulting in a periodic modulation of the critical current and a non-trivial correlation between the conductance in the normal state and the supercurrent. We find, in good agreement with existing theory11, that the product of the critical current and the normal state resistance becomes an oscillating function, in contrast to being constant as in previously explored regimes.