We show how algorithmic differentiation can be used to efficiently implement the pathwise derivative method for the calculation of option sensitivities using Monte Carlo simulations. The main practical difficulty of the pathwise derivative method is that it requires the differentiation of the payout function. For the type of structured options for which Monte Carlo simulations are usually employed, these derivatives are typically cumbersome to calculate analytically, and too time consuming to evaluate with standard finite-difference approaches. In this paper we address this problem and show how algorithmic differentiation can be employed to calculate these derivatives very efficiently and with machine-precision accuracy. We illustrate the basic workings of this computational technique by means of simple examples, and we demonstrate with several numerical tests how the pathwise derivative method combined with algorithmic differentiation - especially in the adjoint mode - can provide speed-ups of several orders of magnitude with respect to standard methods.