A reciprocating engine that functions following thermodynamic cycles such as the CARNOT, STIRLING and OTTO after appropriate modifications. Its main characteristics are that it consists of a number of chambers equivalent to the phases of the thermodynamic cycle it follows in each instance and that for the approach of the theoretical cycle a displacement of the working medium from chamber to chamber in a cyclical pattern is performed. The cylinders are interconnected by pipes and their pistons are connected to a crankshaft with a 180° phase difference. During the shaft rotation the working medium is displaced from cylinder to cylinder and at the same time moves to a different phase of the thermodynamic cycle. The cylinders have different piston displacements, which correspond to the volume of the working medium at the end of each thermodynamic process. The thermal exchanges between the working medium and the hot and cold reservoirs as well as among phases of the thermodynamic cycle are carried out by heat exchangers introduced to the pipes. The engine can be used for the production of mechanical or cooling work.