The short-distance coefficients for the color-octet 3S1 term in the fragmentation function for a gluon to split into heavy quarkonium states is calculated to order alpha_s^2. The gauge-invariant definition of the fragmentation function by Collins and Soper is employed. Ultraviolet divergences are removed using the MS-bar renormalization procedure. The longitudinal term in the fragmentation function agrees with a previous calculation by Beneke and Rothstein. The next-to-leading order correction to the transverse term disagrees with a previous calculation.