The inventory routing problem (IRP) is an integrated inventory and transportation planning problem that jointly determines the replenishment schedules for a given set of retailers, and the routing decisions for a supplier that distributes a product to the retailers over a finite planning horizon typically consisting of multiple periods. In the classical IRP, retailers are assumed to accept deliveries at any time during a given period. However, this assumption does not always hold in practice. Although the supplier is the central decision maker, the retailers may also have operational restrictions preventing them from receiving deliveries at arbitrary times. With this motivation, we study the IRP with time windows and develop an exact algorithm to solve it. In particular, we propose a new formulation and an efficient branch-price-and-cut algorithm, which, to the best of our knowledge, is the first exact approach specifically designed for solving the IRPTW. Our formulation involves both arc and route based variables to obtain an easier structure in the pricing problems. We use valid inequalities --originally derived for the lot sizing problem-- to strengthen our formulation. The results of a computational study conducted on a set of newly generated benchmark instances demonstrate the effectiveness of our algorithm, which is capable of identifying optimal or fairly good solutions to medium and large problem instances in reasonable computation times.