A Smart City integrates various key elements, including technology, finance, government, and management, highlighting specific connectivity requirements. Wireless technologies such as ZigBee, Bluetooth, 4G, WiMax, WiFi, and LTE have established themselves as solutions for communication in smart city initiatives. However, as the prevalence of unlicensed noise and bandwidth issues increases, IoT is being utilized to address these challenges. This article addresses the problems of resource allocation (RA) and routing by proposing an enhanced Swarm Distributed Energy-Efficient Clustering Scheme (ES-DEEC) protocol for IoT networks. This method, based on hybrid optimization techniques (PSO-GWO), focuses on data clustering and meta-heuristic approaches for optimizing IoT devices and gateway allocation. It also introduces a nature-inspired swarm optimization method for routing. The performance of the ES-DEEC method is demonstrated using MATLAB simulations, with experimental results compared to the existing ECRR method in terms of energy consumption (EC), Packet Delivery Ratio (PDR), network lifetime (NLT), and network throughput (TH).