A wireless sensor network (WSN) is a collection of sensor nodes that dynamically self-organize themselves into a wireless network without the utilization of any preexisting infrastructure. One of the major problems in WSNs is the energy consumption, whereby the network lifetime is dependent on this factor. In this paper, we propose an optimal routing protocol for WSN inspired by the foraging behavior of ants. The ants try to find existing paths between the source and base station. Furthermore, we have combined this behavior of ants with fuzzy logic in order for the ants to make the best decision. In other words, the fuzzy logic is applied to make the use of these paths optimal. Our algorithm uses the principles of the fuzzy ant colony optimization routing (FACOR) to develop a suitable problem solution. The performance of our routing algorithm is evaluated by Network Simulator 2 (NS2). The simulation results show that our algorithm optimizes the energy consumption amount, decreases the number of routing request packets, and increases the network lifetime in comparison with the original AODV.