As a result of the Internet of Things (IoT), smart city infrastructure has been able to advance, enhancing efficiency and enabling remote management. Despite this, this interconnectivity poses significant security and privacy concerns, as cyberthreats are rapidly adapting to exploit IoT vulnerabilities. In order to safeguard privacy and ensure secure IoT operations, robust security strategies are necessary. To detect anomalies effectively, intrusion detection systems (IDSs) must employ sophisticated algorithms capable of handling complex and voluminous datasets. A novel approach to IoT security is presented in this paper, which focuses on safeguarding smart vertical networks (SVNs) integral to sector-specific IoT implementations. It is proposed that a deep learning-based method employing a stacking deep ensemble model be used, selected for its superior performance in managing large datasets and its ability to learn intricate patterns indicative of cyberattacks. Experimental results indicate that the model is exceptionally accurate in identifying cyberthreats, exceeding other models, with a 99.8% detection rate for the ToN-IoT dataset and 99.6% for the InSDN dataset. The paper aims not only to introduce a robust algorithm for IoT security, but also to demonstrate its efficacy through comprehensive testing. We selected a deep learning ensemble model due to its proven track record in similar applications and its ability to maintain the integrity of IoT systems in smart cities.