Threat detection in a Cyber-Physical System (CPS) platform is a key feature of ensuring the reliability and security of these connected methods, but digital elements interface with the physical world. CPS platforms are popular in sectors like healthcare, industrial automation, smart cities, and transportation making them vulnerable to different cyber-attacks. Threat detection in CPS contains the detection and mitigation of cybersecurity risks, which disrupt physical processes, compromise data integrity, and potentially cause safety concerns. Machine learning (ML) and deep learning (DL) systems are exploited for detecting anomalies by learning the normal behaviour forms of the CPS and recognizing deviations. This study presents an Automated Threat Detection using the Flamingo Search Algorithm with Optimal Deep Learning (ATD-FSAODL) technique in a CPS environment. Initially, the ATD-FSAODL technique applies FSA-based feature subset selection to elect the better group of features. In addition, the ATD-FSAODL technique makes use of a modified Elman Spike Neural Network (MESNN) model for threat recognition and classification. Finally, the slime mold algorithm (SMA) is used for the optimal selection of the parameters related to the MESNN approach to ensure that the threat detection rate is improved. To estimate the solution of the ATD-FSAODL technique, a sequence of simulations can be carried out on benchmark databases. The performance values portray the capable solution of the ATD-FSAODL methodology with other methods with a maximum accuracy of 99.58%, precision of 99.58%, recall of 99.58%, F-score of 99.58%, and MCC of 99.16%.