Quantum rate processes in condensed phase systems are often computed by combining quantum and classical descriptions of the dynamics. An algorithm for simulating the quantum-classical Liouville equation, which describes the dynamics of a quantum subsystem coupled to a classical bath, is presented in this paper. The algorithm is based on a Trotter decomposition of the quantum-classical propagator, in conjunction with Monte Carlo sampling of quantum transitions, to yield a surface-hopping representation of the dynamics. An expression for the nonadiabatic propagator that is responsible for quantum transitions and associated bath momentum changes is derived in a form that is convenient for Monte Carlo sampling and exactly conserves the total energy of the system in individual trajectories. The expectation values of operators or quantum correlation functions can be evaluated by initial sampling of quantum states and use of quantum-classical Liouville dynamics for the time evolution. The algorithm is tested by calculations on the spin-boson model, for which exact quantum results are available, and is shown to reproduce the exact results for stronger nonadiabatic coupling and much longer times using fewer trajectories than other schemes for simulating quantum-classical Liouville dynamics.