This article describes a continuous-time Markov approach to the riskneutral pricing of a credit default swap with counterparty risk. The key parameters in the approach are the transition rates, which naturally incorporate the ideas of contagion. Correlation (which is time-dependent) is a derived quantity, which results from contagion. An expansion in powers of a small parameter (a risk-neutral default probability) allows analytic formulae to be obtained for all relevant quantities. Thus, the problem of the calibration of the model to the market prices of the bonds of the reference entity and the counterparty, as well as to the credit default swap spreads of the reference entity (which are independent of the bond spreads in the case of counterparty risk), is solved. This is done with the help of analytic results for the spread of a credit default swap with counterparty risk, as well as for other derivative prices. A comparison with results produced by the market-standard Gaussian copula approach indicates that the market-standard approach could be significantly improved by allowing the copula correlation coefficient to be time-dependent.