Finding reliable and efficient routes is a persistent problem in megacities. To address this problem, several algorithms have been proposed. However, there are still areas of research that require attention. Many traffic-related problems can be resolved with the help of smart cities that incorporate the Internet of Vehicles (IoV). On the other hand, due to rapid increases in the population and automobiles, traffic congestion has become a serious concern. This paper presents a heterogeneous algorithm called ant-colony optimization with pheromone termite (ACO-PT), which combines two state-of-the-art algorithms, pheromone termite (PT) and ant-colony optimization (ACO), to address efficient routing to improve energy efficiency, increase throughput, and shorten end-to-end latency. The ACO-PT algorithm seeks to provide an effective shortest path from a source to a destination for drivers in urban areas. Vehicle congestion is a severe issue in urban areas. To address this issue, a congestion-avoidance module is added to handle potential overcrowding. Automatic vehicle detection has also been a challenging issue in vehicle management. To address this issue, an automatic-vehicle-detection (AVD) module is employed with ACO-PT. The effectiveness of the proposed ACO-PT algorithm is demonstrated experimentally using network simulator-3 (NS-3) and Simulation of Urban Mobility (SUMO). Our proposed algorithm is compared with three cutting-edge algorithms. The results demonstrate that the proposed ACO-PT algorithm is superior to earlier algorithms in terms of energy usage, end-to-end delay, and throughput.