An automated drug delivery system that provides closed-loop feedback control of the ventricular rate during atrial fibrillation is described. The control system was designed using a mathematical model of the effect of esmolol infusion on the ventricular rate. The model was developed in system identification experiments with anesthetized dogs in which atrial fibrillation was induced and maintained by rapid atrial pacing. A control system of variable structure, which incorporates a transient controller and a regulator, was designed to perform satisfactorily over a wide range of subject responses to drug infusion. The transient controller brings the ventricular rate to the setpoint with little overshoot. When the ventricular rate is near the setpoint, the drug infusion rate is calculated by the regulator. The drug infusion rate is constrained to ensure smooth transitions in the hemodynamic state of the patient and for safety. Feasibility of the system was demonstrated in computer simulations and animal experiments.