This paper proposes a new approach for the optimal operation and control of a Proton Exchange Membrane Fuel Cell (PEMFC) in a microgrid. This approach is based on a bi-level optimization architecture: an economic optimization for the operational management at the higher level, and a control-oriented optimization problem, based on a Reference Governor (RG) approach, at the lower level. The economic optimization imposes flexibility in the power production of the PEMFC. This operating behavior may cause violation of the equipment operating limits when switching from one power level to another, thus provoking the premature aging phenomena that leads to poor performance of the system. With the RG real-time control approach, the operating limits of the system are being respected despite the forced variability and better performances are obtained compared to the classical Proportional-Integer (PI) controller. This work focuses on the stack’s temperature as the key process variable to control. The effectiveness of the control approach is proved by a significant reduction in the sudden changes of the PEMFC stack temperature by up to 85% via a real case study.