We prove a structure theorem for triangulated Calabi–Yau categories: an algebraic 2-Calabi–Yau triangulated category over an algebraically closed field is a cluster category if and only if it contains a cluster-tilting subcategory whose quiver has no oriented cycles. We prove a similar characterization for higher cluster categories. As an application to commutative algebra, we show that the stable category of maximal Cohen–Macaulay modules over a certain isolated singularity of dimension 3 is a cluster category. This implies the classification of the rigid Cohen–Macaulay modules first obtained by Iyama and Yoshino. As an application to the combinatorics of quiver mutation, we prove the non-acyclicity of the quivers of endomorphism algebras of cluster-tilting objects in the stable categories of representation-infinite preprojective algebras. No direct combinatorial proof is known as yet. In the appendix, Michel Van den Bergh gives an alternative proof of the main theorem by appealing to the universal property of the triangulated orbit category.