Objective: With the growing demand for livers in the field of transplantation, interest in normothermic ex vivo machine perfusion (NMP) has increased in recent years. This may open the door for novel therapeutic interventions such as repair of suboptimal grafts. For successful long-term NMP of livers, blood glucose (BG) levels need to be maintained in a close to physiological range. Methods: We present an "automated insulin delivery" (AID) system integrated into an NMP system, which automatically adjusts insulin infusion rates based on continuous BG measurements in a closed loop manner during ex vivo pig and human liver perfusion. An online glucose sensor for continuous glucose monitoring was integrated and evaluated in blood. A model based and a proportional controller were implemented and compared in their ability to maintain BG within the physiological range. Results: The continuous glucose sensor is capable of measuring BG directly in human and pig blood for multiple days with an average error of 0.6 mmol/L. There was no significant difference in the performance of the two controllers in terms of their ability to keep BG in the physiological range. With the integrated AID, BG was controlled within the physiological range on average in 80% and 76% of the perfusion time for human and pig livers, respectively. Conclusion: The presented work offers a method and shows the feasibility to maintain BG in the physiological range for multiple (up to ten) days during ex vivo liver perfusion with the help of an automated AID. Significance: Maintaining BG within the physiological range is inevitable to enable long-term ex situ liver perfusion.