The precise alignment of a high-performance, wide-field telescope is a key factor to ensure its imaging quality. The sharpness function of far-field images combined with an optimization algorithm is one of the most commonly used telescope alignment methods because of its advantages of having a concise measurement system, a simple calculation process, and wide application fields. In this paper, a Cassegrain telescope with two mirrors is aligned by maximizing the sharpness function of far-field images using the stochastic parallel gradient descent algorithm. To verify the effects of this method, both numerical simulations and experiments are implemented. The misalignments are corrected only after a few iterations, indicating that the stochastic parallel gradient descent algorithm can align the telescope rapidly. What's more, wavefront errors are measured using a Shack-Hartmann wavefront sensor to confirm the accuracy. The results show that this method can align a telescope that is in a misaligned working state with large misalignment errors rapidly and accurately, and the image quality after correction is improved greatly. (C) 2020 Optical Society of America