The security travel of freight vehicles is of high societal concern and is the key issue for urban managers to effectively supervise and assess the possible social security risks. With continuous improvements in motion-based technology, the trajectories of freight vehicles are readily available, whose unusual changes may indicate hidden urban risks. Moreover, the increasing high spatial and temporal resolution of trajectories provides the opportunity for the real-time recognition of the abnormal or risky vehicle motion. However, the existing researches mainly focus on the spatial anomaly detection, and there are few researches on the real-time temporal anomaly detection. In this paper, a grid-based algorithm, which combines the spatial and temporal anomaly detection, is proposed for tracing the risk of urban freight vehicles trajectory by considering local temporal window. The travel time probability distribution of vehicle historical trajectory is analyzed to meet the time complexity requirements of real-time anomaly calculation. The developed methodology is applied to a case study in Beijing to demonstrate its accuracy and effectiveness.