This paper studies a pricing problem for a single-server queue where customers arrive according to a Poisson process. For each arriving customer, the service provider announces a price rate and system wait time. In response, the customer decides whether to join the queue, and, if so, the duration of the service time. The objective is to maximize either the long-run average revenue or social welfare. We formulate this problem as a continuous-time control model whose optimality conditions involve solving a set of delay differential equations. We develop an innovative method to obtain the optimal control policy, whose structure reveals interesting insights. The optimal dynamic price rate policy is not monotone in the wait time. That is, in addition to the congestion effect (the optimal price rate increases in the wait time), we find a compensation effect, meaning that the service provider should lower the price rate when the wait time is longer than a threshold. Compared with the prevalent static pricing policy, our optimal dynamic pricing policy improves the objective value through admission control, which, in turn, increases the utilization of the server. In a numerical study, we find that our revenue-maximizing pricing policy outperforms the best static pricing policy, especially when the arrival rate is low, and customers are impatient. Interestingly, the revenue-maximizing policy also improves social welfare over the static pricing policy in most of the tested cases. We extend our model to consider nonlinear pricing and heterogeneous customers. Nonlinear pricing may improve the revenue significantly, although linear pricing is easier to implement. For the hetergeneous customer case, we obtain similar policy insights as our base model. This paper was accepted by Baris Ata, stochastic models and simulation. Supplemental Material: The online appendix is available at https://doi.org/10.1287/mnsc.2022.4474 .