Anomalous human trajectory detection is a critical task in security surveillance in working areas. To identify anomalous human trajectories, understanding features of their movement plays an important role. Therefore, in this work, a Transformer encoder and self-organizing map-based model called TENSO is proposed to learn trajectory characteristics for detecting anomalies. In particular, the proposed model learns the internal characteristics of normal trajectories and clusters of normal trajectory representations in a latent space. To learn the internal characteristics of normal trajectories, the encoder of Transformer with a self-attention mechanism first encodes trajectories into sequences of embedding vectors of trajectory points in the latent space. Then, a decoder reconstructs the trajectories from the latent space. In addition, to learn clusters of normal trajectory representations in the latent space, the self-organizing map (SOM) layer is used, which gets its input as the output of the Transformer encoder. In the training phase, the TENSO model is trained using a total loss of trajectory reconstruction and SOM losses. In the anomaly detection phase, a test trajectory is evaluated to determine whether it is an anomaly based on trajectory reconstruction errors and the quantization error on the SOM. In this phase, a new metric is proposed which, namely WS, is the weighted sum of recall and precision to choose the appropriate threshold for detecting anomalies. The TENSO modelbased framework is evaluated using two real trajectory datasets: MIT Badge and sCREEN. Experimental results show that the proposed framework identifies anomalies effectively and outperforms the baselines.INDEX TERMS Anomalous trajectory detection, indoor human trajectory, Transformer encoder, Selforganizing map.