Quantum maximum-distance-separable (MDS) codes form an important class of quantum codes. It is very hard to construct quantum MDS codes with relatively large minimum distance. In this paper, based on classical constacyclic codes, we construct two classes of quantum MDS codes with parameters $$\begin{aligned}{}[[\lambda (q-1),\lambda (q-1)-2d+2,d]]_q \end{aligned}$$ where $$2\le d\le (q+1)/2+\lambda -1$$ , and $$q+1=\lambda r$$ with $$r$$ even, and $$\begin{aligned}{}[[\lambda (q-1),\lambda (q-1)-2d+2,d]]_q \end{aligned}$$ where $$2\le d\le (q+1)/2+\lambda /2-1$$ , and $$q+1=\lambda r$$ with $$r$$ odd. The quantum MDS codes exhibited here have parameters better than the ones available in the literature.