There are two connected events here: the electron transport chain, and chemiosmosis.
The electron transport chain is imbedded in the membrane of the cristae of the mitochondria.
The electron transport chain consists of a series of proteins that first pick up electrons (the protein is reduced), then lets them go (oxidized). At each step, a little energy is released.
The electrons to pass down the chain come from all of the NADH and FADH2 molecules, which pick up electrons in glycolysis and the Krebs cycle.
The energy released by the passage of electrons down the electron transport chain goes to pump protons (H+ ions) across the membrane of the cristae to the inside.
Oxygen is the final electron acceptor and, along with some spare protons, combines to form water.
As protons build up inside the innermembrane space of the cristae, a pressure develops. This pressure establishes a gradient, and protons will tend to move from an area of higher concentration to an area of lower concentration. (Remember diffusion and osmosis?)
The only place for those protons to go is back out through special enzymes imbedded in the membrane called ATP synthase enzymes.
The specific event of forced diffusion of protons out through the ATP synthase is called chemiosmosis.
Here is the grand finale.
As protons rush through the ATP synthase enzymes, energy is released. This energy goes to attach phosphates back onto ATP. ATP is phosphorylated! (This is the action of chemiosmosis.)