The long-term accumulation of ammonia nitrogen in aquaculture seriously affects the life of fish and even causes large-scale death. Moreover, when the concentration of ammonia nitrogen starts to accumulate, it is a judgment standard to provide early warning through the changes in fish behavior to prevent excessive ammonia nitrogen in water. Therefore, this paper proposes a novel approach to monitoring water quality for aquaculture based on deep learning and three-dimensional movement trajectory. The improved YOLOv8 model was used as the object detection approach to obtain three-dimensional position information of fish by combining Kalman filter, Kuhn Munkres (KM) algorithm, and Kernelized Correlation Filters (KCF) algorithm. The proposed approach was evaluated in the recovery experiment of acute ammonia nitrogen stress of sturgeon, bass, and crucian. The experimental results show that the precision, recall, [email protected], and [email protected]:0.95 of the improved YOLOv8 model are 0.964, 0.914, 0.979, and 0.602, respectively. In addition, the proposed three-dimensional positioning approach can qualitatively and quantitatively analyze the fish behavior in different stages and further explores the fish behavior changes through behavior trajectories, volumes of exercise, spatial distribution, and movement velocity. This research provides a new method and idea for studying the abnormal behavior of aquatic animals under ammonia nitrogen stress and has theoretical and practical significance.