Currently, plenty of sensor devices have come to use which communicate with each other using Wireless Sensor Networks (WSN). The increase in the number of sensor devices increases the rate of congestion and traffic, as numerous sensed data try to reach the destination node, than the channel capacity. As a result, there is a loss of packets, degradation in throughput, and an increase in energy consumption, thereby degrading the efficiency and robustness of WSN. To address the above-mentioned issues, the paper has proposed a traffic-oriented and resource-oriented congestion control mechanism namely Rank-based Ant-Colony Optimization and Random Forest Regression (RAC-RFR). The Rank-based Ant-Colony Optimization is used for detecting multiple congestion-free paths based on a ranking system that ranks based on the length of the path. The Random Forest Regression is Machine learning-based optimal pathfinder, which chooses the optimal congestion-free path among the paths found by RAC based on the packet loss rate and path rank. From the experimental results conducted the proposed approach showed enhanced performance in terms of throughput, delay, packet loss, queue size, congestion level, and energy consumption against existing congestion control methodologies.