When two superconductors are electrically connected by a weak link-such as a tunnel barrier-a zero-resistance supercurrent can flow1,2. This supercurrent is carried by Cooper pairs of electrons with a combined charge of twice the elementary charge,e.The 2echarge quantum is clearly visible in the height of voltage steps in Josephson junctions under microwave irradiation, and in the magnetic flux periodicity ofh/2e(wherehis Planck's constant) in superconducting quantum interference devices2. Here we study supercurrents through a quantum dot created in a semiconductor nanowire by local electrostatic gating. Owing to strong Coulomb interaction, electrons only tunnel one-by-one through the discrete energy levels of the quantum dot. This nevertheless can yield a supercurrent when subsequent tunnel events are coherent3-7. These quantum coherent tunnelling processes can result in either a positive or a negative supercurrent, that is, in a normal or a π-junction8-10, respectively. We demonstrate that the supercurrent reverses sign by adding a single electron spin to the quantum dot. When excited states of the quantum dot are involved in transport, the supercurrent sign also depends on the character of the orbital wavefunctions.