We consider the capacitated p-median problem (CPMP) in which a set of n customers must be partitioned into p disjoint clusters so that the total dissimilarity within each cluster is minimized and constraints on maximum cluster capacities are met. The dissimilarity of a cluster is computed as the sum of the dissimilarities existing between each entity of the cluster and the median associated with such cluster. In this paper we present an exact algorithm for solving the CPMP based on a set partitioning formulation of the problem. A valid lower bound to the optimal solution cost is obtained by combining two different heuristic methods for solving the dual of the LP-relaxation of the exact formulation. Computational tests on problems proposed in the literature and on new sets of test problems show the effectiveness of the proposed algorithm.