This paper considers an M/M/1 queueing system with dynamically controlled arrival and service rates. At each arrival or service completion epoch, a decision maker chooses a pair of arrival and service rates from a finite set, and the system operates under these rates until the next arrival or service completion. There is a switching cost for changing the rates, and there is a cost per unit time of holding customers and using the arrival and service rates. The results describe natural conditions on the costs under which an optimal policy for either the discounted-cost or average-cost criterion is a hysteretic policy. Such a policy increases the service rate and decreases the arrival rate as the queue length increases. Furthermore, the control exhibits a stickiness or resistance to change, called hysteresis, due to the switching costs.