It has a part that is embedded in a mitochondrial membrane and works as a rotor. The other part is sticking out from the membrane and is responsible for synthesis of ATP from ADP and phosphate. An off-axis part of the rotor pushes the stator, it changes shape and pushes ADP and phosphate together, until they fuse to ATP.
To make the rotor move, it makes use of membrane potential. One side of the membrane has a lot more H⁺ (just protons, really) than the other. The excess H⁺ want to go to the other side. The membrane doesn’t let them through. It is hydrophobic on the inside, so it does’t let through anything charged (like H⁺) or polar (like water). This is the potential and it has quite a lot of energy. ATP synthase lets the H⁺ through by binding them to the rotor in the membrane in a particular place and releases them in another in such a way that forces the rotor to turn almost a full turn before they can leave and stops it from rotating the other way. As mentioned, the rotation is transfered to the stator, changing its shape and thus creating ATP. As a side note, multiple H⁺ are bound on the rotor along its circumference, so each rotation is powered by the potential energy of multiple protons.
Of course, it’s a bit more complicated than that, but I don’t think there’s anything downright wrong or misleading in what I wrote. I hope I managed to make it understandable. Also, I recommend animations of the synthase on youtube.