The mechanism by which ADP is phosphorylated to ATP in mitochondria and chloroplasts. The energy released as electrons pass down an electron transport chain is used to establish a proton gradient across an inner membrane of the organelle; when protons subsequently flow down this electrochemical gradient, the potential energy released is captured in the terminal phosphate bonds of ATP.