The x-ray spectrum recorded by a photon-counting x-ray detector (PCXD) is distorted due to the following physical effects which are independent of the count rate: finite energy-resolution, Compton scattering, charge-sharing, and Kescape. If left uncompensated, the spectral response (SR) of a PCXD due to the above effects will result in image artifacts and inaccurate material decomposition. We propose a new SR compensation (SRC) algorithm using the sinogram restoration approach. The two main contributions of our proposed algorithm are: (1) our algorithm uses an efficient conjugate gradient method in which the first and second derivatives of the cost functions are directly calculated analytically, whereas a slower optimization method that requires numerous function evaluations was used in other work; (2) our algorithm guarantees convergence by combining the non-linear conjugate gradient method with line searches that satisfy Wolfe conditions, whereas the algorithm in other work is not backed by theorems from optimization theory to guarantee convergence. In this study, we validate the performance of the proposed algorithm using computer simulations. The bias was reduced to zero from 11%, and image artifacts were removed from the reconstructed images. Quantitative K-edge imaging in possible only when SR compensation is done.