The invention relates to a method for controlling the driving engine (M) and hydraulic pumps (PUMP1, PUMP2) of a hydraulic machine (10), the method comprising: —driving at least one hydraulic variable displacement pump (PUMP1, PUMP2) that supplies pressurized medium to the hydraulic system of the machine by the driving engine (M), —determining the working pressure pi, p2) and volume flow (Qip, Q2p) output from at least one hydraulic pump (PUMP1, PUMP2), —determining the torque (T-ip, T2p) required of at least one hydraulic pump (PUMP1, PUMP2) or the total torque (Tpk0k) required by two or more hydrau¬lic pumps (PUMP1, PUMP2) by means of the working pressure (p-i, p2) and volume flow (Qip, Q2p) of pressurized medium output from at least one hydraulic pump (PUMP1, PUMP2), as well as the rotation speed (i) of the driving engine (M); —controlling the rotation speed (i) of the driving engine (M) and the dis¬placement (V1p, V2p) of at least one hydraulic pump (PUMP1, PUMP2) auto¬matically so that the torque (Td, Tdeff) produced by the driving engine approaches the torque (Tip, T2p) required by at least one hydraulic pump (PUMP1, PUMP2) driven by the driving engine (M), or the total torque (Tpk0k) of two or more hydraulic pumps (PUMP1, PUMP2) in such a way that the volume flow (Q1p, Q2p) produced by at least one hydraulic pump (PUMP1, PUMP2) will remain unchanged. The invention also relates to a system for controlling the driving engine (M) and hydraulic pumps (PUMP1, PUMP2) of a hydraulic machine (10), as well as a pile driving rig comprising the system according to the invention.