Wireless sensor networks (WSNs) have been recognized as one of the most essential technologies of the 21st century. The applications of WSNs are rapidly increasing in almost every sector because they can be deployed in areas where cable and power supply are difficult to use. In the literature, different methods have been proposed to minimize energy consumption of sensor nodes so as to prolong WSNs utilization. In this article, we propose an efficient routing protocol for data transmission in WSNs; it is called Energy-Efficient Hierarchical routing protocol for wireless sensor networks based on Fog Computing (EEHFC). Fog computing is integrated into the proposed scheme due to its capability to optimize the limited power source of WSNs and its ability to scale up to the requirements of the Internet of Things applications. In addition, we propose an improved ant colony optimization (ACO) algorithm that can be used to construct optimal path for efficient data transmission for sensor nodes. The performance of the proposed scheme is evaluated in comparison with P-SEP, EDCF, and RABACO schemes. The results of the simulations show that the proposed approach can minimize sensor nodes’ energy consumption, data packet losses and extends the network lifetime.