Wireless sensor networks (WSNs) are one of the most essential technologies in the 21st century due to their increase in various application areas and can be deployed in areas where cable and power supply are difficult to use. However, sensor nodes that form these networks are energyconstrained because they are powered by non-rechargeable small batteries. Thus, it is imperative to design a routing protocol that is energy efficient and reliable to extend network lifetime utilization. In this article, we propose an improved ant colony optimization algorithm: a technique for extending wireless sensor networks lifetime utilization called AMACO. We present a new clustering method to avoid the overhead that is usually involved during the election of cluster heads in the previous approaches and energy holes within the network. Moreover, fog computing is integrated into the scheme due to its ability to optimize the limited power source of WSNs and to scale up to the requirements of the Internet of Things applications. All the data packets received by the fog nodes are transmitted to the cloud for further analysis and storage. An improved ant colony optimization (ACO) algorithm is used to construct optimal paths between the cluster heads and fog nodes for a reliable end-to-end data packets delivery. The simulation results show that the network lifetime in AMACO increased by 22.0%, 30.7%, and 32.0% in comparison with EBAR, IACO-MS, and RRDLA before the first node dies (FND) respectively. It increased by 15.2%, 18.4%, and 33.5% in comparison with EBAR, IACO-MS, and RRDLA before half nodes die (HND) respectively. Finally, it increased by 28.2%, 24.9%, and 58.9% in comparison with EBAR, IACO-MS, and RRDLA before the last node dies (LND) respectively.