Inverse dynamics is a technique in which measured kinematics and, possibly, external forces are used to calculate net joint torques in a rigid body linked segment model. However, kinematics and forces are usually not consistent due to incorrect modelling assumptions and measurement errors. This is commonly resolved by introducing ‘residual forces and torques’ which compensate for this problem, but do not exist in reality. In this study a constrained optimization algorithm is proposed that finds the kinematics that are mechanically consistent with measured external forces and mimic the measured kinematics as closely as possible. The algorithm was tested on datasets containing planar kinematics and ground reaction forces obtained during human walking at three velocities (0.8 m/s, 1.25 and 1.8 m/s). Before optimization, the residual force and torque were calculated for a typical example. Both showed substantial values, indicating the necessity of developing a mechanically consistent algorithm. The proposed optimization algorithm converged to a solution in which the residual forces and torques were zero, without changing the ground reaction forces and with only minor changes to the measured kinematics. When using a rigid body approach, our algorithm ensures a consistent description of forces and kinematics, thereby improving the validity of calculated net joint torque and power values.