Congestion is an essential problem in wireless sensor networks. In view of resolving the problem of congestion, a novel congestion control algorithm is proposed based on rate optimization. It performs the estimation of congestion level in the cluster and between the clusters based on the distribution of queue length of the node, and uses the maximum utility function to optimize the sending rate of source nodes. In addition, the algorithm adopts the cluster structure to prolong the system lifetime. The simulation results show that ROCC can prevent effectively and alleviate the congestion, and dynamic adjust the sending rate of source nodes while controlling congestion.