We compute the one-loop QCD amplitude for the process gg -> Q (Q) over bar in dimensional regularization through order epsilon(2) in the dimensional regulator and for arbitrary quark mass values. This result is an ingredient of the next-to-next-to-leading order cross section for heavy-quark production at hadron colliders. The calculation is performed in conventional dimensional regularization using well-known reduction techniques as well as a method based on recent ideas for the functional form of one-loop integrands in four dimensions.