We consider the problem of controlling the charging of electric vehicles (EVs) connected to a single charging station that follows an aggregated power setpoint from a main controller of the local distribution grid. To cope with volatile resources such as load or distributed generation, this controller manages in real time the flexibility of the energy resources in the distribution grid and uses the charging station to adapt its power consumption. The aggregated power setpoint might exhibit rapid variations due to other volatile resources of the local distribution grid. However, large power jumps and minicycles could increase the EV battery wear. Hence, our first challenge is to properly allocate the powers to EVs so that such fluctuations are not directly absorbed by EV batteries. We assume that EVs are used as flexible loads and that they do not supply the grid. As the EVs have a minimum charging power that cannot be arbitrarily small, and as the rapid fluctuations of the aggregated power setpoint could lead to frequent disconnections and reconnections, the second challenge is to avoid these disconnections and reconnections. The third challenge is to fairly allocate the power in the absence of the information about future EVs arrivals and departures, as this information might be unavailable in practice. To address these challenges, we formulate an online optimization problem and repeatedly solve it by using a mixed-integer-quadratic program. To do so in real time, we develop a heuristic that reduces the number of integer variables. We validate our method by simulations with real-world data.