A novel distributed feedback optimization-based controller for electric vehicle (EV) chargers and renewable energy sources (RESs) in distribution systems is proposed. The proposed controller utilizes the flexibility in EV chargers’ active and reactive power consumption to offer the desirable vehicle-to-grid services. Instead of using the conventional cascaded PI controllers, a new optimization-based approach is proposed to control RESs to track their power injection setpoints. The proposed controller formulates the control targets as a single constrained optimization problem, i.e., to minimize the critical bus voltage magnitude deviations while driving RESs to follow their power setpoints, thereby fulfilling the EV charging requirements and regulating their power outputs and bus voltage magnitudes to stay within their limits. A distributed feedback optimization-based control algorithm is designed for EV chargers and RESs to steer the system trajectories of the distribution systems towards the optimal solution of the formulated optimization problem. Simulation results show that the proposed controller can always steer the test system to the optimal solution of the optimization problem. The advantages of the real-time vehicle-to-grid power compensation of EV chargers are also demonstrated.