Since 2014, the Formula 1 power unit has consisted of an internal combustion engine equipped with an electrified turbocharger and a powerful electric motor with regenerative braking and boosting capabilities. This hybrid electric powertrain is controlled by a dedicated energy management system, whose decisions significantly influence the achievable lap time, as well as the fuel and electric energy consumption. Therefore, feedback control algorithms must be designed in order to follow lap time optimal strategies and properly react to disturbances. In this paper, we propose a real-time control algorithm based on a two-level model predictive control (MPC) scheme. A high-level controller, based on a convex model of the system, is used to periodically update the optimal strategies, whereas a zone MPC scheme is designed as a linear program to follow these trajectories in an optimal way. Each iteration of the low-level MPC can be calculated within few milliseconds, thus allowing for a suitable update frequency. The optimality of the presented controller is verified using a benchmark simulator, and its performance is finally tested on a third-party high-fidelity nonlinear simulator of the race car.