A heat engine (H1; H2) comprising: at least a first and a second pressure container each provided with heating means for heating a gas in the respective container and with cooling means for cooling a gas in the respective container, at least a first and a second cylinder space each having a piston arranged therein to move forth and back in such a manner that, when one of the two cylinder spaces has a decreasing volume the other of the two cylinder spaces has an increasing volume, forward strokes being defined as the strokes in which the first cylinder space has an increasing volume and the second cylinder space has a decreasing volume, gas channels connecting said pressure containers and cylinder spaces to form a closed gas circuit, valves arranged in said gas circuit between the containers and the two cylinder spaces and valve control means arranged to open and close at least two of said valves in order to, in a first phase, heat the first pressure container and cool the second pressure container, and during forward strokes of the piston(s), supply gas from the first pressure container to the first cylinder space, to thereby propel the piston(s), and let gas leave the second cylinder space towards the second pressure container, and to, during return strokes of the piston(s), let gas leave the first cylinder space and let gas enter the second cylinder space, and in a second phase, heat the second pressure container and cool the first pressure container, and during forward strokes of the piston(s), supply gas from the second pressure container to the first cylinder space to thereby propel the piston(s) and allow gas to enter the first pressure container coming from the second cylinder space, and to, during return strokes of the piston(s), let gas leave the first cylinder space and let gas enter the second cylinder space, wherein the first phase and second phase are applied in an alternating manner, characterized in that the heat engine (H1; H2) also comprises a crankshaft and a flywheel , and the piston(s) is/are mechanically connected to the crankshaft and the flywheel for driving them; and the valve control means are arranged to, during operation of the heat engine, close the valve (18a; 21b) that allows the gas to enter one of the cylinder spaces between 50-70% of the stroke of the cylinder to thereby propel the piston(s) before the end of the stroke of the cylinder. at least a first and a second pressure container each provided with heating means for heating a gas in the respective container and with cooling means for cooling a gas in the respective container, at least a first and a second cylinder space each having a piston arranged therein to move forth and back in such a manner that, when one of the two cylinder spaces has a decreasing volume the other of the two cylinder spaces has an increasing volume, forward strokes being defined as the strokes in which the first cylinder space has an increasing volume and the second cylinder space has a decreasing volume, gas channels connecting said pressure containers and cylinder spaces to form a closed gas circuit, valves arranged in said gas circuit between the containers and the two cylinder spaces and valve control means arranged to open and close at least two of said valves in order to, the heat engine (H1; H2) also comprises a crankshaft and a flywheel , and the piston(s) is/are mechanically connected to the crankshaft and the flywheel for driving them; and the valve control means are arranged to, during operation of the heat engine, close the valve (18a; 21b) that allows the gas to enter one of the cylinder spaces between 50-70% of the stroke of the cylinder to thereby propel the piston(s) before the end of the stroke of the cylinder. <EOS>