Like other enzymes, the activity of FF ATP synthase is reversible. Large-enough quantities of ATP cause it to create a transmembrane proton gradient, this is used by fermenting bacteria that do not have an electron transport chain, but rather hydrolyze ATP to make a proton gradient, which they use to drive flagella and the transport of nutrients into the cell.
In respiring bacteria under physiological conditions, ATP synthase, in general, runs in the opposite direction, creating ATP while using the proton motive force created by the electron transport chain as a source of energy. The overall process of creating energy in this fashion is termed oxidative phosphorylation.
The same process takes place in the mitochondria, where ATP synthase is located in the inner mitochondrial membrane and the F-part projects into the mitochondrial matrix. By pumping proton cations into the matrix, the ATP-synthase converts ADP into ATP.