Positioning of workpieces in machining operations has a direct influence on the machined features. Workpiece datum errors are one of the error sources that affect the workpiece positioning in the fixture. In this article, a systematic method is presented for eliminating the effect of datum errors on the workpiece machined features in five-axis machining. In this method, the effect of datum errors on the machined features is mathematically modelled using homogenous transformation matrix, and the error vector on the workpiece machining surface is obtained. The error vector consists of position and orientation errors of the tool in workpiece coordinate system. In this work, a compensation module is developed, which is applied to the machining codes of the workpiece. The input to this module is the datum errors and initial NC-codes. The output of the module is the modified NC-codes. For verifying the method, two cases are studied, which are related to five-axis drilling and five-axis free-form milling. Using the compensation method, the position, orientation and form errors are decreased considerably. The results confirm that this method can be used for compensating the datum errors effectively.