Hey, look at ATP synthase with me for a second. It’s literally a molecular rotary motor with a crank shaft, embedded in a membrane holding a proton reservoir.
(In eukaryotes like us, that membrane is the inner mitochondrial membrane; in prokaryotes it’s usually the inner membrane of the cell. Either way its job is to turn ADP into ATP, which will turn back to ADP after it does work in the cell.)
There are pumps elsewhere on the membrane that force protons (H+) in. When they come out, they come out through the ATP synthase, turning the turny bit. When 10 protons go through, the head makes a complete turn, minting 3 ATP molecules.
This thing is 10-20 nanometers long!
Also neat: it’s universally conserved across all life. Not in the exact same form, but recognizably the same thing:
Life began around 3.5 billion years ago. The oldest two domains of life – bacteria and archaea – diverged really early. “Have different cell membrane and cell wall composition” early. So ATP synthase arose around the time life itself did, and has persisted for three quarters of Earth’s lifetime.