We present an accurate method for calculating hyperfine coupling constants (HFCCs) based on the complete active space second-order perturbation theory (CASPT2) with full internal contraction. The HFCCs are computed as a first-order property using the relaxed CASPT2 spin-density matrix that takes into account orbital and configurational relaxation due to dynamical electron correlation. The first-order unrelaxed spin-density matrix is calculated from one- and two-body spin-free counterparts that are readily available in the CASPT2 nuclear gradient program [M. K. MacLeod and T. Shiozaki, J. Chem. Phys. 142, 051103 (2015)], whereas the second-order part is computed directly using the newly extended automatic code generator. The relaxation contribution is then calculated from the so-called Z-vectors that are available in the CASPT2 nuclear gradient program. Numerical results are presented for the CN and AlO radicals, for which the CASPT2 values are comparable (or, even superior in some cases) to the ones computed by the coupled-cluster and density matrix renormalization group methods. The HFCCs for the hexaaqua complexes with VII, CrIII, and MnII are also presented to demonstrate the accuracy and efficiency of our code.