Energy discriminating, photon-counting detectors (PCDs) are an emerging technology for computed tomography (CT) with various potential benefits for clinical CT. The photon energies measured by PCDs can be distorted due to the interactions of a photon with the detector and the interaction of multiple coincident photons. These effects result in distorted recorded x-ray spectra which may lead to artifacts in reconstructed CT images and inaccuracies in tissue identification. Model-based compensation techniques have the potential to account for the distortion effects. This approach requires only a small number of parameters and is applicable to a wide range of spectra and count rates, but it needs an accurate model of the spectral distortions occurring in PCDs. The purpose of this study was to develop a model of those spectral distortions and to evaluate the model using a PCD (model DXMCT-1; DxRay, Inc., Northridge, CA) and various x-ray spectra in a wide range of count rates. The authors hypothesize that the complex phenomena of spectral distortions can be modeled by: (1) separating them into count-rate independent factors that we call the spectral response effects (SRE), and count-rate dependent factors that we call the pulse pileup effects (PPE), (2) developing separate models for SRE and PPE, and (3) cascading the SRE and PPE models into a combined SRE+PPE model that describes PCD distortions at both low and high count rates. The SRE model describes the probability distribution of the recorded spectrum, with a photo peak and a continuum tail, given the incident photon energy. Model parameters were obtained from calibration measurements with three radioisotopes and then interpolated linearly for other energies. The PPE model used was developed in the authors' previous work [K. Taguchi et al., "Modeling the performance of a photon counting x-ray detector for CT: Energy response and pulse pileup effects," Med. Phys. 38(2), 1089-1102 (2011)]. The agreement between the x-ray spectra calculated by the cascaded SRE+PPE model and the measured spectra was evaluated for various levels of deadtime loss ratios (DLR) and incident spectral shapes, realized using different attenuators, in terms of the weighted coefficient of variation (COVW), i.e., the root mean square difference weighted by the statistical errors of the data and divided by the mean. At low count rates, when DLR < 10%, the distorted spectra measured by the DXMCT-1 were in agreement with those calculated by SRE only, with COVW's less than 4%. At higher count rates, the measured spectra were also in agreement with the ones calculated by the cascaded SRE+PPE model; with PMMA as attenuator, COVW was 5.6% at a DLR of 22% and as small as 6.7% for a DLR as high as 55%. The x-ray spectra calculated by the proposed model agreed with the measured spectra over a wide range of count rates and spectral shapes. The SRE model predicted the distorted, recorded spectra with low count rates over various types and thicknesses of attenuators. The study also validated the hypothesis that the complex spectral distortions in a PCD can be adequately modeled by cascading the count-rate independent SRE and the count-rate dependent PPE.