Mitochondria, bacteria and chloroplasts use the free energy stored in transmembrane ion gradients to manufacture ATP by the action of ATP synthase. This enzyme consists of two principal domains. The asymmetric membrane-spanning F0 portion contains the proton channel, and the soluble F1 portion contains three catalytic sites which cooperate in the synthetic reactions. The flow of protons through F0 is thought to generate a torque which is transmitted to F1 by an asymmetric shaft, the coiled-coil gamma-subunit. This acts as a rotating 'cam' within F1, sequentially releasing ATPs from the three active sites. The free-energy difference across the inner membrane of mitochondria and bacteria is sufficient to produce three ATPs per twelve protons passing through the motor. It has been suggested that this proton motive force biases the rotor's diffusion so that F0 constitutes a rotary motor turning the gamma shaft. Here we show that biased diffusion, augmented by electrostatic forces, does indeed generate sufficient torque to account for ATP production. Moreover, the motor's reversibility-supplying torque from ATP hydrolysis in F1 converts the motor into an efficient proton pump-can also be explained by our model.