Recently, the extensive use of Internet of Things (IoT) applications has a stronger impact and greater contribution to the development of the smart city. A smart city (SC) uses IoT-based technologies, applications, and communications for maximizing operational efficacy and improving the service quality of providers and the living standard of people. With the development of SC networks, there also comes the augmented menace of cybersecurity attacks and threats. IoT gadgets within an SC network were linked to sensors connected to huge cloud servers and are vulnerable to malicious threats and attacks. Therefore, it is significant to formulate techniques for preventing such assaults and protecting IoT gadgets from failures. This article develops a new transient search algorithm with optimal stacked sparse autoencoder (TSA-OSSAE) based cyber threat detection in IoT-enabled SC applications. The presented TSA-OSSAE technique majorly focuses on the recognition of cyber threats to attain security in the SC. To attain this, the projected TSA-OSSAE system follows TSA based feature selection approach to reduce computational complexity. Besides, the TSA-OSSAE technique applies the SSAE model for cyber threat detection. At last, the hyperparameters of the SSAE approach are optimally chosen by utilizing of multi-versus optimizer (MVO) algorithm. The experimental result analysis of the TSA-OSSAE technique was performed by using the TON_IoT telemetry database. The simulation outcomes signify the promising performance of the TSA-OSSAE methodology over other existing techniques.