In this work an automatic control strategy is presented for the simultaneous control of oxygen and carbon dioxide blood gas partial pressures to be used during cardiopulmonary bypass surgery with heart-lung machine support. As the exchange of blood gases in the artificial extracorporeal lung is a highly nonlinear process comprising varying time delays, uncertainties, and time-varying parameters, it is currently being controlled manually by specially trained perfusionist staff. The new control strategy includes a feedback linearization routine with augmented time-delay compensation and two external linear gain-scheduled controllers, for partial oxygen and carbon dioxide pressures. The controllers were robustly tuned and tested in simulations with a detailed artificial lung (oxygenator) model in cardiopulmonary bypass conditions. Furthermore, the controllers were implemented in an ex vivo experiment using fresh porcine blood as a substitute fluid and a special deoxygenation technique to simulate a patient undergoing cardiopulmonary bypass. Both controllers showed robust stability during the experiments and a good disturbance rejection to extracorporeal blood flow changes. This automatic control strategy is proposed to improve patient's safety by fast control reference tracking and good disturbance rejection under varying conditions.