The purpose of this paper is to derive the generalized conjugate residual (GCR) algorithm for finding the least squares solution on a class of Sylvester matrix equations. We prove that if the system is inconsistent, the least squares solution can be obtained with infinite iterative steps in the absence of round-off errors. Furthermore, we provide a method for choosing the initial matrix to obtain the minimum norm least squares solutionof the problem. Finally, we give some numerical examples to illustrate the performance of GCR algorithm.