Existing end-to-end congestion control algorithms, in Transmission Control Protocol (TCP), use packet loss and queueing delay for congestion detection, and use static control laws to adjust the sending rate and to control the congestion. This approach presupposes that the network, and its interaction with the congestion control mechanism, is static or quasi-static. In practice, the state of the network continuously changes over time, resulting in suboptimal performance of existing algorithms. The article proposes an optimal control approach that solves a dynamical function derived using queuing theory, based on Little's law. The proposed control depends on the rates of change of the average occupancy (DataInFlight) and average response time (round-trip-time), respectively, with respect to the average arrival rate (sending rate). This results in damped harmonic oscillating trajectory. In terms of the average goodput, the proposed mechanism performs better than widely used algorithms, such as TcpCubic and TcpBbr. Similar to TcpBbr, the scheme satisfies Kleinrock's optimality condition for an optimal queuing system, by keeping the average occupancy close to one bandwidth-delay-product and the queueing delay low.