With the continuous increase of maritime traffic, developing an efficient and accurate model for ship trajectory anomaly detection has become crucial for ensuring maritime transportation safety. The high complexity and variability of the marine environment lead to diverse ship trajectory patterns, making it challenging to learn effective trajectory representations for accurately identifying anomalies. We thus proposed an unsupervised deep learning model called STAD for ship trajectory anomaly detection in ocean to address this challenge. Concretely, STAD leverages offset reconstruction-based representation learning and a deep Gaussian Mixture Model (GMM) estimation network to learn the underlying complex clustering patterns of ship trajectories and utilize the learned patterns to enhance trajectory anomaly detection. Extensive experiments on multiple AIS datasets indicate that our model significantly outperforms existing methods in detecting multiple representative types of ship trajectory anomalies, including shift deviation, abnormal heading, and abnormal speeding. This study could help closely monitor the status of ship movement and detect abnormal behaviors in advance, thus benefiting maritime safety.