Congestion in wireless sensor networks (WSNs) is an unavoidable issue in today’s scenario, where data traffic increased to its aggregated capacity of the channel. The consequence of this turns in to overflowing of the buffer at each receiving sensor nodes which ultimately drops the packets, reduces the packet delivery ratio, and degrades throughput of the network, since retransmission of every unacknowledged packet is not an optimized solution in terms of energy for resource-restricted sensor nodes. Routing is one of the most preferred approaches for minimizing the energy consumption of nodes and enhancing the throughput in WSNs, since the routing problem has been proved to be an NP-hard and it has been realized that a heuristic-based approach provides better performance than their traditional counterparts. To tackle all the mentioned issues, this paper proposes an efficient congestion avoidance approach using Huffman coding algorithm and ant colony optimization (ECA-HA) to improve the network performance. This approach is a combination of traffic-oriented and resource-oriented optimization. Specially, ant colony optimization has been employed to find multiple congestion-free alternate paths. The forward ant constructs multiple congestion-free paths from source to sink node, and backward ant ensures about the successful creation of paths moving from sink to source node, considering energy of the link, packet loss rate, and congestion level. Huffman coding considers the packet loss rate on different alternate paths discovered by ant colony optimization for selection of an optimal path. Finally, the simulation result presents that the proposed approach outperforms the state of the art approaches in terms of average energy consumption, delay, and throughput and packet delivery ratio.