Respiratory motion causes artifacts in slow-rotating cone-beam (CB) computed tomography (CT) images acquired for example for image guidance of radiotherapy. Respiration-correlated CBCT has been proposed to correct for the respiratory motion, but the use of a subset of the CB projections to reconstruct each frame of the 4D CBCT image limits their quality, thus requiring a longer acquisition time. Another solution is motion-compensated CBCT which consists of reconstructing a single 3D CBCT image at a reference position from all the CB projections by using an estimate of the respiratory motion in the reconstruction algorithm. In this paper, we propose a method for motion-compensated CBCT which allows to reconstruct the image on-the-fly, i.e. concurrent with acquisition. Before the CB acquisition, a model of the patient motion over the respiratory cycle is estimated from the planning 4D CT. The respiratory motion is then computed on-the-fly from this model using a respiratory signal extracted from the CB projections and incorporated into the motion-compensated CBCT reconstruction algorithm. The proposed method is evaluated on 26 CBCT scans of 3 patients acquired with two protocols used for static and respiration-correlated CBCT respectively. Our results show that this method provides CBCT images within a few seconds after the end of the acquisition where most of the motion artifacts have been removed.