As the prevalence of autism spectrum disorder (ASD) increases globally, more and more patients need to receive timely diagnosis and treatment to alleviate their suffering. However, the current diagnosis method of ASD still adopts the subjective symptom-based criteria through clinical observation, which is time-consuming and costly. In recent years, functional magnetic resonance imaging (fMRI) neuroimaging techniques have emerged to facilitate the identification of potential biomarkers for diagnosing ASD. In this study, we developed a deep learning framework named spatial–temporal Transformer (ST-Transformer) to distinguish ASD subjects from typical controls based on fMRI data. Specifically, a linear spatial–temporal multi-headed attention unit is proposed to obtain the spatial and temporal representation of fMRI data. Moreover, a Gaussian GAN-based data balancing method is introduced to solve the data unbalance problem in real-world ASD datasets for subtype ASD diagnosis. Our proposed ST-Transformer is evaluated on a large cohort of subjects from two independent datasets (ABIDE I and ABIDE II) and achieves robust accuracies of 71.0% and 70.6%, respectively. Compared with state-of-the-art methods, our results demonstrate competitive performance in ASD diagnosis.