Rational use of urban underground space (UUS) and public transportation transfer underground can solve urban traffic problems. Accurate short-term prediction of passenger flow can ensure the efficient, safe, and comfortable operation of subway stations. However, complex and nonlinear interdependencies between time steps and time series complicate such predictions. This study considered temporal patterns across multiple time steps and selected relevant information on short-term passenger flow for prediction. A hybrid model based on the temporal pattern attention (TPA) mechanism and the long short-term memory (LSTM) network was developed (i.e., TPA-LSTM) for predicting the future number of passengers in subway stations. The TPA mechanism focuses on the hidden layer output values of different time steps in history and of the current time as well as correlates these output values to improve the accuracy of the model. The card swiping data from the Hangzhou Metro automatic fare collection system in China were used for verification and analysis. This model was compared with a convolutional neural network (CNN), LSTM, and CNN-LSTM. The results showed that the TPA-LSTM outperformed the other models with good applicability and accuracy. This study provides a theoretical basis for the pre-allocation of subway resources to avoid subway station crowding and stampede accidents.