To help improve the performance of congestion avoidance protocols like Transmission Control Protocol (TCP) and to limit the impact of non-adaptive UDP-based applications, the Internet Engineering Task Force has recommended the widespread deployment of active queue management schemes. We describe in this paper a new Random Early Detection (RED) algorithm for congestion control called Dynamic-RED (DRED) from a gradient optimization perspective. One of the goals of RED schemes is to stabilize the queue lengths in routers. However, the current version of RED does not succeed in this goal because the equilibrium queue length strongly depends on the number of active TCP connections. Using a simple optimization technique, DRED randomly discards packets with a load-dependent probability when a buffer in a router gets congested. DRED is also able to stabilize a router queue occupancy at a level independent of the number of active connections over a wide range of load levels. This is done without estimating the number of active TCP connections or flows and without collecting or analyzing state information on individual flows.