Gas expands when heated, and contracts when cooled. Stirling engines move the gas from the hot side of the engine, where it expands, to the cold side, where it contracts.
When there is a temperature difference between upper displacer space and lower displacer space, the engine pressure is changed by the movement of the displacer. The pressure increases when the displacer is located in the upper part of the cylinder (and most of the air is on the hot lower side). The pressure decreases when the displacer is moved to the lower part of the cylinder. The displacer only moves the air back and forth from the hot side to the cold side. It does not operate the crankshaft and the engine. In other words, the connecting rod to the displacer could be a string in this engine and it would still work.
When the engine pressure reaches its maximum because of the motion of the displacer, a power piston is pushed by the expanding gas adding energy to the crankshaft. The power piston should ideally be 90 degrees out of phase with the displacer piston. The displacer type Stirling engine is operated by the power of the power piston.
A special thanks to Koichi Hirata for the excellent illustrations!