We present families of quantum error-correcting codes which are optimal in the sense that the minimum distance is maximal. These maximum distance separable (MDS) codes are defined over q-dimensional quantum systems, where q is an arbitrary prime power. It is shown that codes with parameters 〚n, n - 2d + 2, d〛q exist for all 3≤n≤q and 1≤d≤n/2+1. We also present quantum MDS codes with parameters 〚q2, q2-2d+2, d〛q for 1≤d≤q which additionally give rise to shortened codes 〚q2-s, q2-2d+2-s, d〛q for some s.