Maritime anomaly detection can improve the situational awareness of vessel traffic supervisors and reduce maritime accidents. In order to better detect anomalous behaviour of a vessel in real time, a method that consists of a Density-Based Spatial Clustering of Applications with Noise (DBSCAN) algorithm and a recurrent neural network is presented. In the method presented, the parameters of the DBSCAN algorithm were determined through statistical analysis, and the results of clustering were taken as the traffic patterns to train a recurrent neural network composed of Long Short-Term Memory (LSTM) units. The neural network was applied as a vessel trajectory predictor to conduct real-time maritime anomaly detection. Based on data from the Chinese Zhoushan Islands, experiments verified the applicability of the proposed method. The results show that the proposed method can detect anomalous behaviours of a vessel regarding speed, course and route quickly.