Predicting the position of a vessel at a specific time in the future is at the core of many maritime applications. The Automatic Identification System (AIS) provides rich information to enable this task. However, vessel trajectory forecasting using AIS data is challenging, even for modern machine learning/deep learning models, because motion data in general, and AIS data in particular, are complex and multimodal. In this paper, we tackle those difficulties by introducing a novel discrete, high-dimensional representation of AIS data and a new loss function to explicitly account for heterogeneity and multimodality. The proposed model -- referred to as TrAISformer -- is a modified transformer network that extracts long-term correlations of AIS trajectories in the proposed enriched space to forecast the positions of vessels after several hours. We report experimental results on real, public AIS data. TrAISformer significantly outperforms state-of-the-art methods and reaches a mean prediction performance below 10 nautical miles up to ~10 hours.