Fuel has chemical energy stored in its structure. When it mixes with oxygen and you heat a small part past its ignition temperature (e.g., with a flame), the fuel and oxygen shift into new, more stable molecules. That shift releases energy as heat, which keeps the reaction going and makes the surrounding gas expand. Engines capture that expanding gas and turn it into motion.
In a piston engine, the gas pushes the piston down and turns a shaft. In a turbine, the gas rushes past blades and spins a shaft. In a boiler-steam system, the fuel heats water into steam, and the steam spins a turbine. All of these machines are doing the same thing: hot gas pushes something and makes it spin.
Once something is spinning, you either use that spinning directly—like wheels on a car or a propeller on a ship—or you connect it to a generator, which is simply a magnet spinning inside coils of wire. Spinning the magnet makes electrons move in the coils, and that movement is electricity. After that, electricity powers anything that needs it: motors turn it back into motion, and electronics use it to run circuits.